<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>roster_core.core &mdash; Roster Core v0.18 documentation</title>
    
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     'v0.18',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="top" title="Roster Core v0.18 documentation" href="../../index.html" />
    <link rel="up" title="Module code" href="../index.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li><a href="../../index.html">Roster Core v0.18 documentation</a> &raquo;</li>
          <li><a href="../index.html" accesskey="U">Module code</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <h1>Source code for roster_core.core</h1><div class="highlight"><pre>
<span class="c">#!/usr/bin/python</span>

<span class="c"># Copyright (c) 2009, Purdue University</span>
<span class="c"># All rights reserved.</span>
<span class="c">#</span>
<span class="c"># Redistribution and use in source and binary forms, with or without</span>
<span class="c"># modification, are permitted provided that the following conditions are met:</span>
<span class="c">#</span>
<span class="c"># Redistributions of source code must retain the above copyright notice, this</span>
<span class="c"># list of conditions and the following disclaimer.</span>
<span class="c">#</span>
<span class="c"># Redistributions in binary form must reproduce the above copyright notice, this</span>
<span class="c"># list of conditions and the following disclaimer in the documentation and/or</span>
<span class="c"># other materials provided with the distribution.</span>
<span class="c">#</span>
<span class="c"># Neither the name of the Purdue University nor the names of its contributors</span>
<span class="c"># may be used to endorse or promote products derived from this software without</span>
<span class="c"># specific prior written permission.</span>
<span class="c">#</span>
<span class="c"># THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot;</span>
<span class="c"># AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE</span>
<span class="c"># IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE</span>
<span class="c"># DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE</span>
<span class="c"># FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL</span>
<span class="c"># DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR</span>
<span class="c"># SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER</span>
<span class="c"># CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,</span>
<span class="c"># OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE</span>
<span class="c"># OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>

<span class="sd">&quot;&quot;&quot;Toplevel core API.&quot;&quot;&quot;</span>

<span class="n">__copyright__</span> <span class="o">=</span> <span class="s">&#39;Copyright (C) 2009, Purdue University&#39;</span>
<span class="n">__license__</span> <span class="o">=</span> <span class="s">&#39;BSD&#39;</span>
<span class="n">__version__</span> <span class="o">=</span> <span class="s">&#39;#TRUNK#&#39;</span>


<span class="kn">import</span> <span class="nn">datetime</span>
<span class="kn">import</span> <span class="nn">uuid</span>

<span class="kn">import</span> <span class="nn">IPy</span>
<span class="kn">import</span> <span class="nn">iscpy</span>

<span class="kn">import</span> <span class="nn">audit_log</span>
<span class="kn">import</span> <span class="nn">constants</span>
<span class="kn">import</span> <span class="nn">errors</span>
<span class="kn">import</span> <span class="nn">helpers_lib</span>
<span class="kn">import</span> <span class="nn">user</span>

<div class="viewcode-block" id="Core"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core">[docs]</a><span class="k">class</span> <span class="nc">Core</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
  <span class="sd">&quot;&quot;&quot;Backend Roster interface.</span>

<span class="sd">  This class is meant to be the only interface to the database for top</span>
<span class="sd">  level programming for a web or xml-rpc interface, or anything else</span>
<span class="sd">  that would need to talk to the database.</span>

<span class="sd">  All errors raised will be a subclass of CoreError.</span>
<span class="sd">  &quot;&quot;&quot;</span>
  <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">user_name</span><span class="p">,</span> <span class="n">config_instance</span><span class="p">,</span> <span class="n">unittest_timestamp</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
      <span class="n">parent_server_instance</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Sets self.db_instance and self.user_instance for usage in the class.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      user_name: string of user name</span>
<span class="sd">      config_instance: instantiated Config class object</span>
<span class="sd">      unittest_timestamp: datetime object timestamp for unit testing</span>
<span class="sd">      parent_server_instance: Roster Server instance that has this </span>
<span class="sd">                              Core instance in it&#39;s core_store.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">dirty</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">unittest_timestamp</span> <span class="o">=</span> <span class="n">unittest_timestamp</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span> <span class="o">=</span> <span class="n">config_instance</span><span class="o">.</span><span class="n">GetDb</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span> <span class="o">=</span> <span class="n">audit_log</span><span class="o">.</span><span class="n">AuditLog</span><span class="p">(</span><span class="n">log_to_syslog</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">log_to_db</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span>
                                           <span class="n">db_instance</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span> <span class="o">=</span> <span class="n">user</span><span class="o">.</span><span class="n">User</span><span class="p">(</span><span class="n">user_name</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="p">,</span>
                                   <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">parent_server_instance</span> <span class="o">=</span> <span class="n">parent_server_instance</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">config_instance</span> <span class="o">=</span> <span class="n">config_instance</span>

<div class="viewcode-block" id="Core.MakeUser"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.MakeUser">[docs]</a>  <span class="k">def</span> <span class="nf">MakeUser</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">user_name</span><span class="p">,</span> <span class="n">access_level</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Create a user.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      user_name: string of user name</span>
<span class="sd">      access_level: int from 0-255 as defined in user.py</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">user_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;user_name&#39;</span><span class="p">:</span> <span class="n">user_name</span><span class="p">,</span>
                 <span class="s">&#39;access_level&#39;</span><span class="p">:</span> <span class="n">access_level</span><span class="p">}</span>

    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">MakeRow</span><span class="p">(</span><span class="s">&#39;users&#39;</span><span class="p">,</span> <span class="n">user_dict</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Core.ListUsers"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.ListUsers">[docs]</a>  <span class="k">def</span> <span class="nf">ListUsers</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">user_name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">access_level</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Lists one or many users, if all args are None then list them all.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      user_name: string of user name</span>
<span class="sd">      access_level: int from 0-255 as defined in user.py</span>

<span class="sd">    Output:</span>
<span class="sd">      dictionary: keyed by the user name with value of access_level.</span>
<span class="sd">        example: {&#39;sharrell&#39;: 128,</span>
<span class="sd">                  &#39;shuey&#39;: 64}</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="s">&#39;ListUsers&#39;</span><span class="p">)</span>
    <span class="n">user_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;user_name&#39;</span><span class="p">:</span> <span class="n">user_name</span><span class="p">,</span>
                 <span class="s">&#39;access_level&#39;</span><span class="p">:</span> <span class="n">access_level</span><span class="p">}</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="n">users</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;users&#39;</span><span class="p">,</span> <span class="n">user_dict</span><span class="p">)</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>

    <span class="n">user_access_level_dict</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="k">for</span> <span class="n">user_dict</span> <span class="ow">in</span> <span class="n">users</span><span class="p">:</span>
      <span class="n">user_access_level_dict</span><span class="p">[</span><span class="n">user_dict</span><span class="p">[</span><span class="s">&#39;user_name&#39;</span><span class="p">]]</span> <span class="o">=</span> <span class="n">user_dict</span><span class="p">[</span><span class="s">&#39;access_level&#39;</span><span class="p">]</span>

    <span class="k">return</span> <span class="n">user_access_level_dict</span>
</div>
<div class="viewcode-block" id="Core.RemoveUser"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.RemoveUser">[docs]</a>  <span class="k">def</span> <span class="nf">RemoveUser</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">user_name</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Removes a user.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      user_name: string of user name</span>

<span class="sd">    Outputs:</span>
<span class="sd">      int: number of rows modified</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">search_user_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;users&#39;</span><span class="p">)</span>
    <span class="n">search_user_dict</span><span class="p">[</span><span class="s">&#39;user_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">user_name</span>
    <span class="n">row_count</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="n">found_user</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;users&#39;</span><span class="p">,</span> <span class="n">search_user_dict</span><span class="p">,</span>
                                              <span class="n">lock_rows</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">if</span><span class="p">(</span> <span class="n">found_user</span> <span class="p">):</span>
          <span class="c"># user_name in users is a unique field so we know there is only one.</span>
          <span class="n">row_count</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">RemoveRow</span><span class="p">(</span><span class="s">&#39;users&#39;</span><span class="p">,</span> <span class="n">found_user</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">row_count</span>
</div>
<div class="viewcode-block" id="Core.UpdateUser"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.UpdateUser">[docs]</a>  <span class="k">def</span> <span class="nf">UpdateUser</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">search_user_name</span><span class="p">,</span> <span class="n">update_user_name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                 <span class="n">update_access_level</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Updates a user.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      search_user_name: string of user name</span>
<span class="sd">      update_user_name: string of user name</span>
<span class="sd">      update_access_level: int from 0-255 as defined in user.py</span>

<span class="sd">    Outputs:</span>
<span class="sd">      int: number of rows modified</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">search_user_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;users&#39;</span><span class="p">)</span>
    <span class="n">search_user_dict</span><span class="p">[</span><span class="s">&#39;user_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">search_user_name</span>
    <span class="n">update_user_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;users&#39;</span><span class="p">)</span>
    <span class="n">update_user_dict</span><span class="p">[</span><span class="s">&#39;user_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">update_user_name</span>
    <span class="n">update_user_dict</span><span class="p">[</span><span class="s">&#39;access_level&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">update_access_level</span>
    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="n">row_count</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">UpdateRow</span><span class="p">(</span><span class="s">&#39;users&#39;</span><span class="p">,</span> <span class="n">search_user_dict</span><span class="p">,</span>
                                               <span class="n">update_user_dict</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>

      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">row_count</span>
</div>
<div class="viewcode-block" id="Core.ListGroups"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.ListGroups">[docs]</a>  <span class="k">def</span> <span class="nf">ListGroups</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;List all groups.</span>

<span class="sd">    Outputs:</span>
<span class="sd">      list of groups</span>
<span class="sd">        example [&#39;cs&#39;, &#39;bio&#39;]</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="s">&#39;ListGroups&#39;</span><span class="p">)</span>
    <span class="n">group_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;groups&#39;</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="n">groups</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;groups&#39;</span><span class="p">,</span> <span class="n">group_dict</span><span class="p">)</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>

    <span class="n">group_list</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">group</span> <span class="ow">in</span> <span class="n">groups</span><span class="p">:</span>
      <span class="n">group_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">group</span><span class="p">[</span><span class="s">&#39;group_name&#39;</span><span class="p">])</span>

    <span class="k">return</span> <span class="n">group_list</span>
</div>
<div class="viewcode-block" id="Core.MakeGroup"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.MakeGroup">[docs]</a>  <span class="k">def</span> <span class="nf">MakeGroup</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">group_name</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Make group.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      group_name: string of group name</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">group_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;groups&#39;</span><span class="p">)</span>
    <span class="n">group_dict</span><span class="p">[</span><span class="s">&#39;group_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">group_name</span>

    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">MakeRow</span><span class="p">(</span><span class="s">&#39;groups&#39;</span><span class="p">,</span> <span class="n">group_dict</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Core.RemoveGroup"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.RemoveGroup">[docs]</a>  <span class="k">def</span> <span class="nf">RemoveGroup</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">group_name</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Remove group.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      group_name: string of group name</span>

<span class="sd">    Outputs:</span>
<span class="sd">      int: number of rows modified</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">group_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;groups&#39;</span><span class="p">)</span>
    <span class="n">group_dict</span><span class="p">[</span><span class="s">&#39;group_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">group_name</span>

    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="n">row_count</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">RemoveRow</span><span class="p">(</span><span class="s">&#39;groups&#39;</span><span class="p">,</span> <span class="n">group_dict</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">row_count</span>
</div>
<div class="viewcode-block" id="Core.UpdateGroup"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.UpdateGroup">[docs]</a>  <span class="k">def</span> <span class="nf">UpdateGroup</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">search_group_name</span><span class="p">,</span> <span class="n">update_group_name</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Update group.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      search_group_name: string of group name</span>
<span class="sd">      update_group_name: string of group name</span>

<span class="sd">    Outputs:</span>
<span class="sd">      int: number of rows modified</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">search_group_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;groups&#39;</span><span class="p">)</span>
    <span class="n">search_group_dict</span><span class="p">[</span><span class="s">&#39;group_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">search_group_name</span>

    <span class="n">update_group_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;groups&#39;</span><span class="p">)</span>
    <span class="n">update_group_dict</span><span class="p">[</span><span class="s">&#39;group_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">update_group_name</span>

    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="n">row_count</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">UpdateRow</span><span class="p">(</span><span class="s">&#39;groups&#39;</span><span class="p">,</span> <span class="n">search_group_dict</span><span class="p">,</span>
                                               <span class="n">update_group_dict</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">row_count</span>
</div>
<div class="viewcode-block" id="Core.ListUserGroupAssignments"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.ListUserGroupAssignments">[docs]</a>  <span class="k">def</span> <span class="nf">ListUserGroupAssignments</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">user_name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">group_name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                               <span class="n">key_by_group</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;List user-group assignments.</span>

<span class="sd">    Assignments can be given as a dictionary of users with lists of groups or</span>
<span class="sd">    as a dictionary of groups as a list of users.</span>

<span class="sd">    Outputs:</span>
<span class="sd">      dictionarie keyed by group or user with values of lists of groups or users</span>
<span class="sd">      depending on key_by_group bool</span>
<span class="sd">        example keyed by user: {&#39;sharrell&#39;: [&#39;cs&#39;, &#39;bio&#39;],</span>
<span class="sd">                                &#39;shuey&#39;: [&#39;cs&#39;]}</span>
<span class="sd">        example keyed by group: {&#39;cs&#39;: [&#39;shuey&#39;, &#39;sharrell&#39;]</span>
<span class="sd">                                 &#39;bio&#39;: [&#39;sharrell&#39;]</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="s">&#39;ListUserGroupAssignments&#39;</span><span class="p">)</span>
    <span class="n">assignment_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;user_group_assignments&#39;</span><span class="p">)</span>
    <span class="n">assignment_dict</span><span class="p">[</span><span class="s">&#39;user_group_assignments_group_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">group_name</span>
    <span class="n">assignment_dict</span><span class="p">[</span><span class="s">&#39;user_group_assignments_user_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">user_name</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="n">assignments</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;user_group_assignments&#39;</span><span class="p">,</span>
                                             <span class="n">assignment_dict</span><span class="p">)</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>

    <span class="n">assignments_dict</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="k">for</span> <span class="n">assignment</span> <span class="ow">in</span> <span class="n">assignments</span><span class="p">:</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">key_by_group</span> <span class="p">):</span>
        <span class="k">if</span><span class="p">(</span> <span class="ow">not</span> <span class="n">assignment</span><span class="p">[</span><span class="s">&#39;user_group_assignments_group_name&#39;</span><span class="p">]</span> <span class="ow">in</span>
            <span class="n">assignments_dict</span> <span class="p">):</span>
          <span class="n">assignments_dict</span><span class="p">[</span>
              <span class="n">assignment</span><span class="p">[</span><span class="s">&#39;user_group_assignments_group_name&#39;</span><span class="p">]]</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="n">assignments_dict</span><span class="p">[</span>
            <span class="n">assignment</span><span class="p">[</span><span class="s">&#39;user_group_assignments_group_name&#39;</span><span class="p">]]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                <span class="n">assignment</span><span class="p">[</span><span class="s">&#39;user_group_assignments_user_name&#39;</span><span class="p">])</span>
      <span class="k">else</span><span class="p">:</span>
        <span class="k">if</span><span class="p">(</span> <span class="ow">not</span> <span class="n">assignment</span><span class="p">[</span><span class="s">&#39;user_group_assignments_user_name&#39;</span><span class="p">]</span> <span class="ow">in</span>
            <span class="n">assignments_dict</span> <span class="p">):</span>
          <span class="n">assignments_dict</span><span class="p">[</span>
              <span class="n">assignment</span><span class="p">[</span><span class="s">&#39;user_group_assignments_user_name&#39;</span><span class="p">]]</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="n">assignments_dict</span><span class="p">[</span>
            <span class="n">assignment</span><span class="p">[</span><span class="s">&#39;user_group_assignments_user_name&#39;</span><span class="p">]]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                <span class="n">assignment</span><span class="p">[</span><span class="s">&#39;user_group_assignments_group_name&#39;</span><span class="p">])</span>

    <span class="k">return</span> <span class="n">assignments_dict</span>
</div>
<div class="viewcode-block" id="Core.MakeUserGroupAssignment"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.MakeUserGroupAssignment">[docs]</a>  <span class="k">def</span> <span class="nf">MakeUserGroupAssignment</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">user_name</span><span class="p">,</span> <span class="n">group_name</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Make user-group assignment.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      group_name: string of group name</span>
<span class="sd">      user_name: string of user name</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">assignment_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;user_group_assignments&#39;</span><span class="p">)</span>
    <span class="n">assignment_dict</span><span class="p">[</span><span class="s">&#39;user_group_assignments_group_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">group_name</span>
    <span class="n">assignment_dict</span><span class="p">[</span><span class="s">&#39;user_group_assignments_user_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">user_name</span>

    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">MakeRow</span><span class="p">(</span><span class="s">&#39;user_group_assignments&#39;</span><span class="p">,</span> <span class="n">assignment_dict</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Core.RemoveUserGroupAssignment"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.RemoveUserGroupAssignment">[docs]</a>  <span class="k">def</span> <span class="nf">RemoveUserGroupAssignment</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">user_name</span><span class="p">,</span> <span class="n">group_name</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Remove user-group.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      group_name: string of group name</span>
<span class="sd">      user_name: string of user name</span>

<span class="sd">    Outputs:</span>
<span class="sd">      int: number of rows modified</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">assignment_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;user_group_assignments&#39;</span><span class="p">)</span>
    <span class="n">assignment_dict</span><span class="p">[</span><span class="s">&#39;user_group_assignments_group_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">group_name</span>
    <span class="n">assignment_dict</span><span class="p">[</span><span class="s">&#39;user_group_assignments_user_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">user_name</span>

    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="n">row_count</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">RemoveRow</span><span class="p">(</span><span class="s">&#39;user_group_assignments&#39;</span><span class="p">,</span>
                                               <span class="n">assignment_dict</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="k">return</span> <span class="n">row_count</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Core.ListACLs"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.ListACLs">[docs]</a>  <span class="k">def</span> <span class="nf">ListACLs</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">acl_name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">cidr_block</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;List one or many acls, if all args are none it will them all, or just</span>
<span class="sd">    search on one more terms.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      acl_name: string of acl name</span>
<span class="sd">      cidr_block: string of valid CIDR block or IP address</span>

<span class="sd">    Outputs:</span>
<span class="sd">      dictionary: keyed by the acl name whos value is a list dictionaries with</span>
<span class="sd">                  the cidr block and range allowed values.</span>
<span class="sd">        example: {&#39;rfc_1918_networks&#39;:   [{&#39;cidr_block&#39;: &#39;192.168/16&#39;},</span>
<span class="sd">                                          {&#39;cidr_block&#39;: &#39;10/8&#39;}],</span>
<span class="sd">                  &#39;university_networks&#39;: [{&#39;cidr_block&#39;: &#39;1.2.3/24&#39;},</span>
<span class="sd">                                          {&#39;cidr_block&#39;: &#39;1.1.1/24&#39;}]}</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="s">&#39;ListACLs&#39;</span><span class="p">)</span>
    <span class="n">acl_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;acl_ranges&#39;</span><span class="p">)</span>
    <span class="n">acl_dict</span><span class="p">[</span><span class="s">&#39;acl_ranges_acl_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">acl_name</span>
    <span class="n">acl_dict</span><span class="p">[</span><span class="s">&#39;acl_range_cidr_block&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">cidr_block</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="n">acls</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;acl_ranges&#39;</span><span class="p">,</span> <span class="n">acl_dict</span><span class="p">)</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>

    <span class="n">acl_cidr_range_dict</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="k">for</span> <span class="n">acl</span> <span class="ow">in</span> <span class="n">acls</span><span class="p">:</span>
      <span class="k">if</span><span class="p">(</span> <span class="ow">not</span> <span class="n">acl_cidr_range_dict</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">acl</span><span class="p">[</span><span class="s">&#39;acl_ranges_acl_name&#39;</span><span class="p">])</span> <span class="p">):</span>
        <span class="n">acl_cidr_range_dict</span><span class="p">[</span><span class="n">acl</span><span class="p">[</span><span class="s">&#39;acl_ranges_acl_name&#39;</span><span class="p">]]</span> <span class="o">=</span> <span class="p">[]</span>
      <span class="n">acl_cidr_range_dict</span><span class="p">[</span><span class="n">acl</span><span class="p">[</span><span class="s">&#39;acl_ranges_acl_name&#39;</span><span class="p">]]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
          <span class="p">{</span><span class="s">&#39;cidr_block&#39;</span><span class="p">:</span> <span class="n">acl</span><span class="p">[</span><span class="s">&#39;acl_range_cidr_block&#39;</span><span class="p">]})</span>

    <span class="k">return</span> <span class="n">acl_cidr_range_dict</span>
</div>
<div class="viewcode-block" id="Core.MakeACL"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.MakeACL">[docs]</a>  <span class="k">def</span> <span class="nf">MakeACL</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">acl_name</span><span class="p">,</span> <span class="n">cidr_block</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Makes an acl from args.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      acl_name: string of acl name</span>
<span class="sd">      cidr_block: string of valid CIDR block or IP address</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">acls_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;acl_name&#39;</span><span class="p">:</span> <span class="n">acl_name</span><span class="p">}</span>
    <span class="n">acl_ranges_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;acl_ranges_acl_name&#39;</span><span class="p">:</span> <span class="n">acl_name</span><span class="p">,</span>
                       <span class="s">&#39;acl_range_cidr_block&#39;</span><span class="p">:</span> <span class="n">cidr_block</span><span class="p">}</span>
    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="k">if</span><span class="p">(</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;acls&#39;</span><span class="p">,</span> <span class="n">acls_dict</span><span class="p">)</span> <span class="p">):</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">MakeRow</span><span class="p">(</span><span class="s">&#39;acls&#39;</span><span class="p">,</span> <span class="n">acls_dict</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">MakeRow</span><span class="p">(</span><span class="s">&#39;acl_ranges&#39;</span><span class="p">,</span> <span class="n">acl_ranges_dict</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span>  <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Core.RemoveACL"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.RemoveACL">[docs]</a>  <span class="k">def</span> <span class="nf">RemoveACL</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">acl_name</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Removes an acl from args. Will also remove relevant acl-view assignments.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      acl_name: string of acl name</span>

<span class="sd">    Outputs:</span>
<span class="sd">      int: number of rows modified</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">acls_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;acl_name&#39;</span><span class="p">:</span> <span class="n">acl_name</span><span class="p">}</span>

    <span class="n">row_count</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="n">row_count</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">RemoveRow</span><span class="p">(</span><span class="s">&#39;acls&#39;</span><span class="p">,</span> <span class="n">acls_dict</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">row_count</span>

</div>
<div class="viewcode-block" id="Core.RemoveCIDRBlockFromACL"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.RemoveCIDRBlockFromACL">[docs]</a>  <span class="k">def</span> <span class="nf">RemoveCIDRBlockFromACL</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">acl_name</span><span class="p">,</span> <span class="n">cidr_block</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Makes CIDR Block from ACL</span>

<span class="sd">    Inputs:</span>
<span class="sd">      acl_name: string of acl name</span>
<span class="sd">      cidr_block: string of valid CIDR block or IP address</span>
<span class="sd">      range_allowed: Int bool of if range should be allowed or denied</span>

<span class="sd">    Outputs:</span>
<span class="sd">      int: number of rows modified</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">acl_ranges_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;acl_ranges_acl_name&#39;</span><span class="p">:</span> <span class="n">acl_name</span><span class="p">,</span>
                       <span class="s">&#39;acl_range_cidr_block&#39;</span><span class="p">:</span> <span class="n">cidr_block</span><span class="p">}</span>

    <span class="n">row_count</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="c"># Will only be one ACL because acl_name/cidr_block are unique</span>
        <span class="n">acls</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;acl_ranges&#39;</span><span class="p">,</span> <span class="n">acl_ranges_dict</span><span class="p">)</span>
        <span class="k">if</span><span class="p">(</span> <span class="n">acls</span> <span class="p">):</span>
          <span class="n">row_count</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">RemoveRow</span><span class="p">(</span><span class="s">&#39;acl_ranges&#39;</span><span class="p">,</span>
                                                  <span class="n">acls</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">row_count</span>

</div>
<div class="viewcode-block" id="Core.ListDnsServers"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.ListDnsServers">[docs]</a>  <span class="k">def</span> <span class="nf">ListDnsServers</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dns_server_name</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;List dns servers.</span>

<span class="sd">    Outputs:</span>
<span class="sd">      dictionary: dictionary of server metadata keyed by server the name.</span>
<span class="sd">        example:</span>
<span class="sd">          {u&#39;dns1&#39;: {</span>
<span class="sd">            &#39;ssh_username&#39;: u&#39;user&#39;,</span>
<span class="sd">            &#39;bind_dir&#39;: u&#39;/etc/bind/&#39;,</span>
<span class="sd">            &#39;test_dir&#39;: u&#39;/etc/bind/test&#39;}}</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="s">&#39;ListDnsServers&#39;</span><span class="p">)</span>
    <span class="n">dns_server_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;dns_servers&#39;</span><span class="p">)</span>
    <span class="n">dns_server_dict</span><span class="p">[</span><span class="s">&#39;dns_server_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">dns_server_name</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="n">dns_servers</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;dns_servers&#39;</span><span class="p">,</span> <span class="n">dns_server_dict</span><span class="p">)</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>

    <span class="n">dns_server_dict</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="k">for</span> <span class="n">dns_server</span> <span class="ow">in</span> <span class="n">dns_servers</span><span class="p">:</span>
      <span class="n">server</span> <span class="o">=</span> <span class="n">dns_server</span><span class="p">[</span><span class="s">&#39;dns_server_name&#39;</span><span class="p">]</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">server</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">dns_server_dict</span> <span class="p">):</span>
        <span class="n">dns_server_dict</span><span class="p">[</span><span class="n">server</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
      <span class="n">dns_server_dict</span><span class="p">[</span><span class="n">server</span><span class="p">][</span>
          <span class="s">&#39;ssh_username&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">dns_server</span><span class="p">[</span><span class="s">&#39;dns_server_ssh_username&#39;</span><span class="p">]</span>
      <span class="n">dns_server_dict</span><span class="p">[</span><span class="n">server</span><span class="p">][</span>
          <span class="s">&#39;test_dir&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">dns_server</span><span class="p">[</span><span class="s">&#39;dns_server_remote_test_directory&#39;</span><span class="p">]</span>
      <span class="n">dns_server_dict</span><span class="p">[</span><span class="n">server</span><span class="p">][</span>
          <span class="s">&#39;bind_dir&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">dns_server</span><span class="p">[</span><span class="s">&#39;dns_server_remote_bind_directory&#39;</span><span class="p">]</span>

    <span class="k">return</span> <span class="n">dns_server_dict</span>
</div>
<div class="viewcode-block" id="Core.MakeDnsServer"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.MakeDnsServer">[docs]</a>  <span class="k">def</span> <span class="nf">MakeDnsServer</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dns_server_name</span><span class="p">,</span> <span class="n">dns_server_ssh_username</span><span class="p">,</span> 
                    <span class="n">dns_server_bind_dir</span><span class="p">,</span> <span class="n">dns_server_test_dir</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Makes one dns server</span>

<span class="sd">    Inputs:</span>
<span class="sd">      dns_server_name: string of the dns server name</span>
<span class="sd">      dns_server_ssh_username: string of the ssh user on the server</span>
<span class="sd">      dns_server_bind_dir: string of the absolute path to the bind directory</span>
<span class="sd">        example: u&#39;/etc/bind/&#39;</span>
<span class="sd">      dns_server_test_dir: string of the absolute path to the test directory</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>
    <span class="n">dns_server_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;dns_servers&#39;</span><span class="p">)</span>
    <span class="n">dns_server_dict</span><span class="p">[</span><span class="s">&#39;dns_server_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">dns_server_name</span>
    <span class="n">dns_server_dict</span><span class="p">[</span><span class="s">&#39;dns_server_ssh_username&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">dns_server_ssh_username</span>
    <span class="n">dns_server_dict</span><span class="p">[</span><span class="s">&#39;dns_server_remote_bind_directory&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">dns_server_bind_dir</span>
    <span class="n">dns_server_dict</span><span class="p">[</span><span class="s">&#39;dns_server_remote_test_directory&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">dns_server_test_dir</span>

    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">MakeRow</span><span class="p">(</span><span class="s">&#39;dns_servers&#39;</span><span class="p">,</span> <span class="n">dns_server_dict</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Core.RemoveDnsServer"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.RemoveDnsServer">[docs]</a>  <span class="k">def</span> <span class="nf">RemoveDnsServer</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dns_server_name</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Removes dns server.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      dns_server_name: string of dns server name</span>

<span class="sd">    Outputs:</span>
<span class="sd">      int: number of rows modified</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">dns_server_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;dns_servers&#39;</span><span class="p">)</span>
    <span class="n">dns_server_dict</span><span class="p">[</span><span class="s">&#39;dns_server_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">dns_server_name</span>
    
    <span class="n">row_count</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="n">found_dns</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;dns_servers&#39;</span><span class="p">,</span> <span class="n">dns_server_dict</span><span class="p">)</span>
        <span class="k">if</span><span class="p">(</span> <span class="nb">len</span><span class="p">(</span><span class="n">found_dns</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="p">):</span>
          <span class="n">dns_server_dict</span><span class="p">[</span><span class="s">&#39;dns_server_ssh_username&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">found_dns</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span>
              <span class="s">&#39;dns_server_ssh_username&#39;</span><span class="p">]</span>
          <span class="n">dns_server_dict</span><span class="p">[</span><span class="s">&#39;dns_server_remote_bind_directory&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">found_dns</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span>
              <span class="s">&#39;dns_server_remote_bind_directory&#39;</span><span class="p">]</span>
          <span class="n">dns_server_dict</span><span class="p">[</span><span class="s">&#39;dns_server_remote_test_directory&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">found_dns</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span>
              <span class="s">&#39;dns_server_remote_test_directory&#39;</span><span class="p">]</span>
          <span class="n">row_count</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">RemoveRow</span><span class="p">(</span><span class="s">&#39;dns_servers&#39;</span><span class="p">,</span> <span class="n">dns_server_dict</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">row_count</span>
</div>
<div class="viewcode-block" id="Core.UpdateDnsServer"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.UpdateDnsServer">[docs]</a>  <span class="k">def</span> <span class="nf">UpdateDnsServer</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">search_dns_server_name</span><span class="p">,</span> <span class="n">update_dns_server_name</span><span class="p">,</span> 
      <span class="n">update_dns_server_ssh_username</span><span class="p">,</span> <span class="n">update_dns_server_bind_dir</span><span class="p">,</span> 
      <span class="n">update_dns_server_test_dir</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Updates dns server</span>

<span class="sd">    Inputs:</span>
<span class="sd">      search_dns_server_name: string of dns server name</span>
<span class="sd">      update_dns_server_name: new string of dns server name</span>
<span class="sd">      update_dns_server_ssh_username: new string of dns server username</span>
<span class="sd">      update_dns_server_bind_dir: new string of path to the bind directory</span>
<span class="sd">      update_dns_server_test_dir: new string of path to the test directory</span>

<span class="sd">    Outputs:</span>
<span class="sd">      int: number of rows modified</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">search_dns_server_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;dns_servers&#39;</span><span class="p">)</span>
    <span class="n">search_dns_server_dict</span><span class="p">[</span><span class="s">&#39;dns_server_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">search_dns_server_name</span>

    <span class="n">update_dns_server_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;dns_servers&#39;</span><span class="p">)</span>
    <span class="n">update_dns_server_dict</span><span class="p">[</span><span class="s">&#39;dns_server_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">update_dns_server_name</span>
    <span class="n">update_dns_server_dict</span><span class="p">[</span>
        <span class="s">&#39;dns_server_ssh_username&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">update_dns_server_ssh_username</span>
    <span class="n">update_dns_server_dict</span><span class="p">[</span>
        <span class="s">&#39;dns_server_remote_bind_directory&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">update_dns_server_bind_dir</span>
    <span class="n">update_dns_server_dict</span><span class="p">[</span>
        <span class="s">&#39;dns_server_remote_test_directory&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">update_dns_server_test_dir</span>

    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="n">row_count</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">UpdateRow</span><span class="p">(</span><span class="s">&#39;dns_servers&#39;</span><span class="p">,</span>
                                               <span class="n">search_dns_server_dict</span><span class="p">,</span>
                                               <span class="n">update_dns_server_dict</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">row_count</span>
</div>
<div class="viewcode-block" id="Core.ListDnsServerSets"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.ListDnsServerSets">[docs]</a>  <span class="k">def</span> <span class="nf">ListDnsServerSets</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dns_server_set_name</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;List all dns server sets</span>

<span class="sd">    Inputs:</span>
<span class="sd">      dns_server_set_name: string of dns server set name</span>

<span class="sd">    Outputs:</span>
<span class="sd">       list of dns server sets</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="s">&#39;ListDnsServerSets&#39;</span><span class="p">)</span>
    <span class="n">dns_server_set_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;dns_server_sets&#39;</span><span class="p">)</span>
    <span class="n">dns_server_set_dict</span><span class="p">[</span><span class="s">&#39;dns_server_set_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">dns_server_set_name</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="n">dns_server_sets</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;dns_server_sets&#39;</span><span class="p">,</span>
                                                 <span class="n">dns_server_set_dict</span><span class="p">)</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>

    <span class="n">dns_server_set_list</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">dns_server_set</span> <span class="ow">in</span> <span class="n">dns_server_sets</span><span class="p">:</span>
      <span class="n">dns_server_set_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">dns_server_set</span><span class="p">[</span><span class="s">&#39;dns_server_set_name&#39;</span><span class="p">])</span>

    <span class="k">return</span> <span class="n">dns_server_set_list</span>
</div>
<div class="viewcode-block" id="Core.MakeDnsServerSet"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.MakeDnsServerSet">[docs]</a>  <span class="k">def</span> <span class="nf">MakeDnsServerSet</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dns_server_set_name</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Make dns server set.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      dns_server_set_name: string of dns server set name</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">dns_server_set_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;dns_server_sets&#39;</span><span class="p">)</span>
    <span class="n">dns_server_set_dict</span><span class="p">[</span><span class="s">&#39;dns_server_set_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">dns_server_set_name</span>

    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">MakeRow</span><span class="p">(</span><span class="s">&#39;dns_server_sets&#39;</span><span class="p">,</span> <span class="n">dns_server_set_dict</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Core.RemoveDnsServerSet"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.RemoveDnsServerSet">[docs]</a>  <span class="k">def</span> <span class="nf">RemoveDnsServerSet</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dns_server_set_name</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Remove dns server set.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      dns_server_set_name: string of dns server set name</span>

<span class="sd">    Outputs:</span>
<span class="sd">      int: number of rows modified</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">dns_server_set_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;dns_server_sets&#39;</span><span class="p">)</span>
    <span class="n">dns_server_set_dict</span><span class="p">[</span><span class="s">&#39;dns_server_set_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">dns_server_set_name</span>

    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="n">row_count</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">RemoveRow</span><span class="p">(</span><span class="s">&#39;dns_server_sets&#39;</span><span class="p">,</span>
                                               <span class="n">dns_server_set_dict</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">row_count</span>
</div>
<div class="viewcode-block" id="Core.UpdateDnsServerSet"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.UpdateDnsServerSet">[docs]</a>  <span class="k">def</span> <span class="nf">UpdateDnsServerSet</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">search_dns_server_set_name</span><span class="p">,</span>
                         <span class="n">update_dns_server_set_name</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Update dns_server_set.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      search_dns_server_set_name: string of dns_server_set name</span>
<span class="sd">      update_dns_server_set_name: string of dns_server_set name</span>

<span class="sd">    Outputs:</span>
<span class="sd">      int: number of rows modified</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">search_dns_server_set_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;dns_server_sets&#39;</span><span class="p">)</span>
    <span class="n">search_dns_server_set_dict</span><span class="p">[</span>
        <span class="s">&#39;dns_server_set_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">search_dns_server_set_name</span>

    <span class="n">update_dns_server_set_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;dns_server_sets&#39;</span><span class="p">)</span>
    <span class="n">update_dns_server_set_dict</span><span class="p">[</span>
        <span class="s">&#39;dns_server_set_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">update_dns_server_set_name</span>

    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="n">row_count</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">UpdateRow</span><span class="p">(</span><span class="s">&#39;dns_server_sets&#39;</span><span class="p">,</span>
                                               <span class="n">search_dns_server_set_dict</span><span class="p">,</span>
                                               <span class="n">update_dns_server_set_dict</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">row_count</span>
</div>
<div class="viewcode-block" id="Core.UpdateDnsServerSetViewAssignments"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.UpdateDnsServerSetViewAssignments">[docs]</a>  <span class="k">def</span> <span class="nf">UpdateDnsServerSetViewAssignments</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">search_dns_server_set_name</span><span class="p">,</span> 
      <span class="n">search_view_name</span><span class="p">,</span> <span class="n">update_view_order</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">update_view_options</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Update dns_server_set&#39;s view order and view options</span>

<span class="sd">    Inputs:</span>
<span class="sd">      search_view_name: string of view name</span>
<span class="sd">      search_dns_server_set_name: string of dns_server_set name</span>
<span class="sd">      update_view_order: int of new view order</span>
<span class="sd">      update_view_options: string of view options,</span>
<span class="sd">        for information on valid view options read:</span>
<span class="sd">          http://www.bind9.net/manual/bind/9.3.2/Bv9ARM.ch06.html#view_statement_grammar</span>

<span class="sd">    Outputs:</span>
<span class="sd">      int: number of rows modified</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">search_dns_server_set_view_assignments_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;dns_server_set_view_assignments&#39;</span><span class="p">)</span>
    <span class="n">search_dns_server_set_view_assignments_dict</span><span class="p">[</span>
        <span class="s">&#39;dns_server_set_view_assignments_dns_server_set_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
            <span class="n">search_dns_server_set_name</span><span class="p">)</span>
    <span class="n">search_dns_server_set_view_assignments_dict</span><span class="p">[</span>
        <span class="s">&#39;dns_server_set_view_assignments_view_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
            <span class="n">search_view_name</span><span class="p">)</span>

    <span class="n">update_dns_server_set_view_assignments_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;dns_server_set_view_assignments&#39;</span><span class="p">)</span>
    <span class="n">update_dns_server_set_view_assignments_dict</span><span class="p">[</span>
        <span class="s">&#39;dns_server_set_view_assignments_dns_server_set_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
            <span class="n">search_dns_server_set_name</span><span class="p">)</span>
    <span class="n">update_dns_server_set_view_assignments_dict</span><span class="p">[</span>
        <span class="s">&#39;dns_server_set_view_assignments_view_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
            <span class="n">search_view_name</span><span class="p">)</span>

    <span class="k">if</span><span class="p">(</span> <span class="n">update_view_order</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="p">):</span>
      <span class="n">update_dns_server_set_view_assignments_dict</span><span class="p">[</span><span class="s">&#39;view_order&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">update_view_order</span>

    <span class="k">if</span><span class="p">(</span> <span class="n">update_view_options</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="p">):</span>
      <span class="n">update_dns_server_set_view_assignments_dict</span><span class="p">[</span><span class="s">&#39;view_options&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
          <span class="n">iscpy</span><span class="o">.</span><span class="n">Serialize</span><span class="p">(</span><span class="n">update_view_options</span><span class="p">))</span>

    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="n">row_count</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">UpdateRow</span><span class="p">(</span>
            <span class="s">&#39;dns_server_set_view_assignments&#39;</span><span class="p">,</span>
            <span class="n">search_dns_server_set_view_assignments_dict</span><span class="p">,</span>
            <span class="n">update_dns_server_set_view_assignments_dict</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">row_count</span>

</div>
<div class="viewcode-block" id="Core.ListDnsServerSetAssignments"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.ListDnsServerSetAssignments">[docs]</a>  <span class="k">def</span> <span class="nf">ListDnsServerSetAssignments</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dns_server_name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                                  <span class="n">dns_server_set_name</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;List dns server set assignments.</span>
<span class="sd">    Inputs:</span>
<span class="sd">      dns_server_name: string of dns server name</span>
<span class="sd">      dns_server_set_name: string of dns server set name</span>

<span class="sd">    Outputs:</span>
<span class="sd">      dictionary keyed by server sets.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="s">&#39;ListDnsServerSetAssignments&#39;</span><span class="p">)</span>
    <span class="n">assignment_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;dns_server_set_assignments&#39;</span><span class="p">)</span>
    <span class="n">assignment_dict</span><span class="p">[</span><span class="s">&#39;dns_server_set_assignments_dns_server_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
        <span class="n">dns_server_name</span><span class="p">)</span>
    <span class="n">assignment_dict</span><span class="p">[</span><span class="s">&#39;dns_server_set_assignments_dns_server_set_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
        <span class="n">dns_server_set_name</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="n">assignments</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;dns_server_set_assignments&#39;</span><span class="p">,</span>
                                             <span class="n">assignment_dict</span><span class="p">)</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>

    <span class="n">assignments_dict</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="k">for</span> <span class="n">assignment</span> <span class="ow">in</span> <span class="n">assignments</span><span class="p">:</span>
      <span class="k">if</span><span class="p">(</span> <span class="ow">not</span> <span class="n">assignment</span><span class="p">[</span><span class="s">&#39;dns_server_set_assignments_dns_server_set_name&#39;</span><span class="p">]</span> <span class="ow">in</span>
          <span class="n">assignments_dict</span> <span class="p">):</span>
        <span class="n">assignments_dict</span><span class="p">[</span><span class="n">assignment</span><span class="p">[</span>
            <span class="s">&#39;dns_server_set_assignments_dns_server_set_name&#39;</span><span class="p">]]</span> <span class="o">=</span> <span class="p">[]</span>
      <span class="n">assignments_dict</span><span class="p">[</span><span class="n">assignment</span><span class="p">[</span>
          <span class="s">&#39;dns_server_set_assignments_dns_server_set_name&#39;</span><span class="p">]]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
              <span class="n">assignment</span><span class="p">[</span><span class="s">&#39;dns_server_set_assignments_dns_server_name&#39;</span><span class="p">])</span>

    <span class="k">return</span> <span class="n">assignments_dict</span>
</div>
<div class="viewcode-block" id="Core.MakeDnsServerSetAssignments"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.MakeDnsServerSetAssignments">[docs]</a>  <span class="k">def</span> <span class="nf">MakeDnsServerSetAssignments</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dns_server_name</span><span class="p">,</span> <span class="n">dns_server_set_name</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Make dns server set assignment.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      dns_server_name: string of dns server name</span>
<span class="sd">      dns_server_set_name: string of dns server set name</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">assignment_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;dns_server_set_assignments&#39;</span><span class="p">)</span>
    <span class="n">assignment_dict</span><span class="p">[</span><span class="s">&#39;dns_server_set_assignments_dns_server_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
        <span class="n">dns_server_name</span><span class="p">)</span>
    <span class="n">assignment_dict</span><span class="p">[</span><span class="s">&#39;dns_server_set_assignments_dns_server_set_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
        <span class="n">dns_server_set_name</span><span class="p">)</span>

    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="n">dns_server_set_assignments</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;dns_server_set_&#39;</span>
            <span class="s">&#39;assignments&#39;</span><span class="p">,</span> <span class="n">assignment_dict</span><span class="p">)</span>
        <span class="k">if</span><span class="p">(</span> <span class="nb">len</span><span class="p">(</span><span class="n">dns_server_set_assignments</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="p">):</span>
          <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span><span class="s">&#39;Dns server set assignment already &#39;</span>
              <span class="s">&#39;exists between server </span><span class="si">%s</span><span class="s"> and set  </span><span class="si">%s</span><span class="s">.&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">dns_server_name</span><span class="p">,</span>
                                                         <span class="n">dns_server_set_name</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">MakeRow</span><span class="p">(</span><span class="s">&#39;dns_server_set_assignments&#39;</span><span class="p">,</span> <span class="n">assignment_dict</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Core.RemoveDnsServerSetAssignments"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.RemoveDnsServerSetAssignments">[docs]</a>  <span class="k">def</span> <span class="nf">RemoveDnsServerSetAssignments</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dns_server_name</span><span class="p">,</span> <span class="n">dns_server_set_name</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Remove a dns server set assignment</span>

<span class="sd">    Inputs:</span>
<span class="sd">      dns_server_name: string of dns server name</span>
<span class="sd">      dns_server_set_name: string of dns server set name</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">assignment_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;dns_server_set_assignments&#39;</span><span class="p">)</span>
    <span class="n">assignment_dict</span><span class="p">[</span><span class="s">&#39;dns_server_set_assignments_dns_server_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
        <span class="n">dns_server_name</span><span class="p">)</span>
    <span class="n">assignment_dict</span><span class="p">[</span><span class="s">&#39;dns_server_set_assignments_dns_server_set_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
        <span class="n">dns_server_set_name</span><span class="p">)</span>

    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="n">row_count</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">RemoveRow</span><span class="p">(</span><span class="s">&#39;dns_server_set_assignments&#39;</span><span class="p">,</span>
                                               <span class="n">assignment_dict</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="k">return</span> <span class="n">row_count</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Core.ListDnsServerSetViewAssignments"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.ListDnsServerSetViewAssignments">[docs]</a>  <span class="k">def</span> <span class="nf">ListDnsServerSetViewAssignments</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">view_name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                                      <span class="n">dns_server_set_name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                                      <span class="n">key_by_view</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;List dns server set view assignments</span>

<span class="sd">    Assignments can be given as a dictionary of dns server names with lists of</span>
<span class="sd">    view names or as a dictionary of view names with lists of dns server names.</span>

<span class="sd">    Outputs:</span>
<span class="sd">      Dictionary keyed by view name or dns server set name with values of</span>
<span class="sd">      lists of tuples of view_name or dns_server_sets with view_order and </span>
<span class="sd">      view options as the second and third members of the tuple.</span>
<span class="sd">        example keyed by view_name:</span>
<span class="sd">           {&#39;view1&#39;: [(&#39;set1&#39;, 1, u&#39;some_view_option;&#39;), </span>
<span class="sd">                      (&#39;set2&#39;, 2, u&#39;&#39;)],</span>
<span class="sd">            &#39;view2&#39;: [(&#39;set2&#39;, 2, u&#39;&#39;)]}</span>
<span class="sd">        example keyed by dns_server_set_name:</span>
<span class="sd">           {&#39;set1&#39;: [(&#39;view1&#39;, 1, u&#39;some_view_option;&#39;)]</span>
<span class="sd">            &#39;set2&#39;: [(&#39;view1&#39;, 1, u&#39;&#39;), </span>
<span class="sd">                     (&#39;view2&#39;, 1, u&#39;&#39;)]}</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="s">&#39;ListDnsServerSetViewAssignments&#39;</span><span class="p">)</span>
    <span class="n">assignment_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;dns_server_set_view_assignments&#39;</span><span class="p">)</span>
    <span class="n">assignment_dict</span><span class="p">[</span><span class="s">&#39;dns_server_set_view_assignments_view_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
        <span class="n">view_name</span><span class="p">)</span>
    <span class="n">assignment_dict</span><span class="p">[</span><span class="s">&#39;dns_server_set_view_assignments_dns_server_set_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
        <span class="n">dns_server_set_name</span><span class="p">)</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="n">assignments</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;dns_server_set_view_assignments&#39;</span><span class="p">,</span>
                                             <span class="n">assignment_dict</span><span class="p">)</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>

    <span class="n">assignments_dict</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="k">for</span> <span class="n">assignment</span> <span class="ow">in</span> <span class="n">assignments</span><span class="p">:</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">key_by_view</span> <span class="p">):</span>
        <span class="k">if</span><span class="p">(</span> <span class="ow">not</span> <span class="n">assignment</span><span class="p">[</span><span class="s">&#39;dns_server_set_view_assignments_view_name&#39;</span><span class="p">]</span> <span class="ow">in</span>
            <span class="n">assignments_dict</span> <span class="p">):</span>
          <span class="n">assignments_dict</span><span class="p">[</span>
              <span class="n">assignment</span><span class="p">[</span><span class="s">&#39;dns_server_set_view_assignments_view_name&#39;</span><span class="p">]]</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="n">assignments_dict</span><span class="p">[</span>
            <span class="n">assignment</span><span class="p">[</span><span class="s">&#39;dns_server_set_view_assignments_view_name&#39;</span><span class="p">]]</span><span class="o">.</span><span class="n">append</span><span class="p">((</span>
                <span class="n">assignment</span><span class="p">[</span>
                    <span class="s">&#39;dns_server_set_view_assignments_dns_server_set_name&#39;</span><span class="p">],</span>
                <span class="n">assignment</span><span class="p">[</span><span class="s">&#39;view_order&#39;</span><span class="p">],</span>
                <span class="n">iscpy</span><span class="o">.</span><span class="n">Deserialize</span><span class="p">(</span><span class="n">assignment</span><span class="p">[</span><span class="s">&#39;view_options&#39;</span><span class="p">])))</span>
      <span class="k">else</span><span class="p">:</span>
        <span class="k">if</span><span class="p">(</span> <span class="ow">not</span> <span class="n">assignment</span><span class="p">[</span>
              <span class="s">&#39;dns_server_set_view_assignments_dns_server_set_name&#39;</span><span class="p">]</span> <span class="ow">in</span>
                  <span class="n">assignments_dict</span> <span class="p">):</span>
          <span class="n">assignments_dict</span><span class="p">[</span>
              <span class="n">assignment</span><span class="p">[</span>
                  <span class="s">&#39;dns_server_set_view_assignments_dns_server_set_name&#39;</span><span class="p">]]</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="n">assignments_dict</span><span class="p">[</span><span class="n">assignment</span><span class="p">[</span>
            <span class="s">&#39;dns_server_set_view_assignments_dns_server_set_name&#39;</span><span class="p">]]</span><span class="o">.</span><span class="n">append</span><span class="p">((</span>
                <span class="n">assignment</span><span class="p">[</span><span class="s">&#39;dns_server_set_view_assignments_view_name&#39;</span><span class="p">],</span>
                <span class="n">assignment</span><span class="p">[</span><span class="s">&#39;view_order&#39;</span><span class="p">],</span>
                <span class="n">iscpy</span><span class="o">.</span><span class="n">Deserialize</span><span class="p">(</span><span class="n">assignment</span><span class="p">[</span><span class="s">&#39;view_options&#39;</span><span class="p">])))</span>

    <span class="k">return</span> <span class="n">assignments_dict</span>
</div>
<div class="viewcode-block" id="Core.MakeDnsServerSetViewAssignments"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.MakeDnsServerSetViewAssignments">[docs]</a>  <span class="k">def</span> <span class="nf">MakeDnsServerSetViewAssignments</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">view_name</span><span class="p">,</span> <span class="n">view_order</span><span class="p">,</span> <span class="n">dns_server_set_name</span><span class="p">,</span>
      <span class="n">view_options</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Make dns server set view assignment</span>

<span class="sd">    Inputs:</span>
<span class="sd">      view_name: string of the view name</span>
<span class="sd">      view_order: order that views should be added to named.conf</span>
<span class="sd">      dns_server_set_name: string of the dns server set name</span>
<span class="sd">      view_options: string of view options, defaults to empty string.</span>
<span class="sd">        for information on valid view options read:</span>
<span class="sd">          http://www.bind9.net/manual/bind/9.3.2/Bv9ARM.ch06.html#view_statement_grammar</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">assignment_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;dns_server_set_view_assignments&#39;</span><span class="p">)</span>
    <span class="n">assignment_dict</span><span class="p">[</span><span class="s">&#39;dns_server_set_view_assignments_view_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">view_name</span>
    <span class="n">assignment_dict</span><span class="p">[</span><span class="s">&#39;dns_server_set_view_assignments_dns_server_set_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
        <span class="n">dns_server_set_name</span><span class="p">)</span>
    <span class="n">assignment_dict</span><span class="p">[</span><span class="s">&#39;view_order&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">view_order</span>
    <span class="n">assignment_dict</span><span class="p">[</span><span class="s">&#39;view_options&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">iscpy</span><span class="o">.</span><span class="n">Serialize</span><span class="p">(</span><span class="n">view_options</span><span class="p">)</span>

    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">MakeRow</span><span class="p">(</span><span class="s">&#39;dns_server_set_view_assignments&#39;</span><span class="p">,</span>
                                 <span class="n">assignment_dict</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Core.RemoveDnsServerSetViewAssignments"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.RemoveDnsServerSetViewAssignments">[docs]</a>  <span class="k">def</span> <span class="nf">RemoveDnsServerSetViewAssignments</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">view_name</span><span class="p">,</span> <span class="n">dns_server_set_name</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Remove dns server set view assignment</span>

<span class="sd">    Inputs:</span>
<span class="sd">      view_name: string of view name</span>
<span class="sd">      dns_server_set_name: string of dns server set name</span>

<span class="sd">    Outputs:</span>
<span class="sd">      int: number of rows modified</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">assignment_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;dns_server_set_view_assignments&#39;</span><span class="p">)</span>
    <span class="n">assignment_dict</span><span class="p">[</span><span class="s">&#39;dns_server_set_view_assignments_view_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">view_name</span>
    <span class="n">assignment_dict</span><span class="p">[</span><span class="s">&#39;dns_server_set_view_assignments_dns_server_set_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
        <span class="n">dns_server_set_name</span><span class="p">)</span>

    <span class="n">row_count</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="n">rows</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;dns_server_set_view_assignments&#39;</span><span class="p">,</span>
                                        <span class="n">assignment_dict</span><span class="p">)</span>
        <span class="k">if</span><span class="p">(</span><span class="n">rows</span><span class="p">):</span>
          <span class="c"># can assume there is only one row because view_name and</span>
          <span class="c"># dns_server_set_name are a unique pair in the sql table</span>
          <span class="n">row_count</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">RemoveRow</span><span class="p">(</span>
              <span class="s">&#39;dns_server_set_view_assignments&#39;</span><span class="p">,</span> <span class="n">rows</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>

      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="k">return</span> <span class="n">row_count</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Core.ListViews"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.ListViews">[docs]</a>  <span class="k">def</span> <span class="nf">ListViews</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Lists all views.</span>

<span class="sd">    Outputs:</span>
<span class="sd">      views_list: List of view names. ex - [u&#39;test_view_1&#39;, u&#39;test_view_2&#39;]</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="s">&#39;ListViews&#39;</span><span class="p">)</span>
    <span class="n">view_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;views&#39;</span><span class="p">)</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="n">views</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;views&#39;</span><span class="p">,</span> <span class="n">view_dict</span><span class="p">)</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>

    <span class="n">views_list</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">view</span> <span class="ow">in</span> <span class="n">views</span><span class="p">:</span>
      <span class="n">views_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">view</span><span class="p">[</span><span class="s">&#39;view_name&#39;</span><span class="p">])</span>

    <span class="k">return</span> <span class="n">views_list</span>

</div>
<div class="viewcode-block" id="Core.ListViewDependencies"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.ListViewDependencies">[docs]</a>  <span class="k">def</span> <span class="nf">ListViewDependencies</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Lists all view dependencies.</span>

<span class="sd">    Outputs:</span>
<span class="sd">      list: list of view dependencies</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="s">&#39;ListViewDependencies&#39;</span><span class="p">)</span>
    <span class="n">view_dep_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;view_dependencies&#39;</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="n">view_deps</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;view_dependencies&#39;</span><span class="p">,</span> <span class="n">view_dep_dict</span><span class="p">)</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
    <span class="n">view_dep_list</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">dep</span> <span class="ow">in</span> <span class="n">view_deps</span><span class="p">:</span>
      <span class="n">view_dep_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">dep</span><span class="p">[</span><span class="s">&#39;view_dependency&#39;</span><span class="p">])</span>
    <span class="k">return</span> <span class="n">view_dep_list</span>
  </div>
<div class="viewcode-block" id="Core.MakeView"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.MakeView">[docs]</a>  <span class="k">def</span> <span class="nf">MakeView</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">view_name</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Makes a view and all of the other things that go with a view.</span>

<span class="sd">    For more information about views please see docstring for</span>
<span class="sd">    MakeViewAssignments.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      view_name: string of view name</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">views_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;views&#39;</span><span class="p">)</span>
    <span class="n">views_dict</span><span class="p">[</span><span class="s">&#39;view_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">view_name</span>
    <span class="n">view_dep_name</span> <span class="o">=</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">_dep&#39;</span> <span class="o">%</span> <span class="n">view_name</span>
    <span class="n">view_dependencies_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;view_dependency&#39;</span><span class="p">:</span> <span class="n">view_dep_name</span><span class="p">}</span>
    <span class="n">view_dependency_assignments_dict</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s">&#39;view_dependency_assignments_view_name&#39;</span><span class="p">:</span> <span class="n">view_name</span><span class="p">,</span>
        <span class="s">&#39;view_dependency_assignments_view_dependency&#39;</span><span class="p">:</span> <span class="n">view_dep_name</span><span class="p">}</span>
    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">MakeRow</span><span class="p">(</span><span class="s">&#39;views&#39;</span><span class="p">,</span> <span class="n">views_dict</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">MakeRow</span><span class="p">(</span><span class="s">&#39;view_dependencies&#39;</span><span class="p">,</span> <span class="n">view_dependencies_dict</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">MakeRow</span><span class="p">(</span><span class="s">&#39;view_dependency_assignments&#39;</span><span class="p">,</span>
                                 <span class="n">view_dependency_assignments_dict</span><span class="p">)</span>

        <span class="n">view_dependency_assignments_dict</span><span class="p">[</span>
          <span class="s">&#39;view_dependency_assignments_view_dependency&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s">u&#39;any&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">MakeRow</span><span class="p">(</span><span class="s">&#39;view_dependency_assignments&#39;</span><span class="p">,</span>
                                 <span class="n">view_dependency_assignments_dict</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Core.RemoveView"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.RemoveView">[docs]</a>  <span class="k">def</span> <span class="nf">RemoveView</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">view_name</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Removes a view.</span>

<span class="sd">    Also removes anything attatched to that view. Including any information</span>
<span class="sd">    about a specific zone in the view and any records in that view.</span>
<span class="sd">    Please point gun away from foot.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      view_name: string of view name</span>

<span class="sd">    Raises:</span>
<span class="sd">      InvalidInputError: Cannot remove view any</span>

<span class="sd">    Outputs:</span>
<span class="sd">      int: number of rows modified</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="k">if</span><span class="p">(</span> <span class="n">view_name</span> <span class="o">==</span> <span class="s">u&#39;any&#39;</span> <span class="p">):</span>
      <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span><span class="s">&#39;Cannot remove view any&#39;</span><span class="p">)</span>
    <span class="n">search_view_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;views&#39;</span><span class="p">)</span>
    <span class="n">search_view_dict</span><span class="p">[</span><span class="s">&#39;view_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">view_name</span>
    <span class="n">view_dep_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;view_dependency&#39;</span><span class="p">:</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">_dep&#39;</span> <span class="o">%</span> <span class="n">view_name</span><span class="p">}</span>
    <span class="n">row_count</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="n">view_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;views&#39;</span><span class="p">,</span> <span class="n">search_view_dict</span><span class="p">,</span>
                                             <span class="n">lock_rows</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">if</span><span class="p">(</span> <span class="n">view_dict</span> <span class="p">):</span>
          <span class="c"># view_name is unique in this table so no need to see if there are</span>
          <span class="c"># multiple rows</span>
          <span class="n">row_count</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">RemoveRow</span><span class="p">(</span><span class="s">&#39;views&#39;</span><span class="p">,</span> <span class="n">view_dict</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
          <span class="n">row_count</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">RemoveRow</span><span class="p">(</span><span class="s">&#39;view_dependencies&#39;</span><span class="p">,</span>
                                                  <span class="n">view_dep_dict</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">row_count</span>
</div>
<div class="viewcode-block" id="Core.UpdateView"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.UpdateView">[docs]</a>  <span class="k">def</span> <span class="nf">UpdateView</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">search_view_name</span><span class="p">,</span> <span class="n">update_view_name</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Updates a view.</span>

<span class="sd">    Also updates anything attatched to that view. Including any information</span>
<span class="sd">    about a specific zone in the view and any records in that view.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      search_view_name: string of view name to be updated</span>
<span class="sd">      update_view_name: string of view name to update with</span>

<span class="sd">    Raises:</span>
<span class="sd">      InvalidInputError: Cannot update view any.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="k">if</span><span class="p">(</span> <span class="n">search_view_name</span> <span class="o">==</span> <span class="s">u&#39;any&#39;</span> <span class="p">):</span>
      <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span><span class="s">&#39;Cannot update view any&#39;</span><span class="p">)</span>

    <span class="n">search_view_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;views&#39;</span><span class="p">)</span>
    <span class="n">search_view_dict</span><span class="p">[</span><span class="s">&#39;view_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">search_view_name</span>
    <span class="n">search_view_dep_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;view_dependency&#39;</span><span class="p">:</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">_dep&#39;</span> <span class="o">%</span> <span class="n">search_view_name</span><span class="p">}</span>

    <span class="n">update_view_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;views&#39;</span><span class="p">)</span>
    <span class="n">update_view_dict</span><span class="p">[</span><span class="s">&#39;view_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">update_view_name</span>

    <span class="n">update_view_dep_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;view_dependencies&#39;</span><span class="p">)</span>
    <span class="n">update_view_dep_dict</span><span class="p">[</span><span class="s">&#39;view_dependency&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">_dep&#39;</span> <span class="o">%</span> <span class="n">update_view_name</span>
    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="n">row_count</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">UpdateRow</span><span class="p">(</span><span class="s">&#39;views&#39;</span><span class="p">,</span> <span class="n">search_view_dict</span><span class="p">,</span>
                                               <span class="n">update_view_dict</span><span class="p">)</span>
        <span class="n">row_count</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">UpdateRow</span><span class="p">(</span><span class="s">&#39;view_dependencies&#39;</span><span class="p">,</span>
                                                <span class="n">search_view_dep_dict</span><span class="p">,</span>
                                                <span class="n">update_view_dep_dict</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">row_count</span>
</div>
<div class="viewcode-block" id="Core.ListViewAssignments"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.ListViewAssignments">[docs]</a>  <span class="k">def</span> <span class="nf">ListViewAssignments</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">view_superset</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">view_subset</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Lists view assignments.</span>

<span class="sd">    For more informaton about view assignments please read the</span>
<span class="sd">    MakeViewAssignment docstring.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      view_superset: string of view name</span>
<span class="sd">      view_subset: string of view name</span>

<span class="sd">    Outputs:</span>
<span class="sd">      dictionary keyed by view supersets with values lists of view subsets</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="s">&#39;ListViewAssignments&#39;</span><span class="p">)</span>
    <span class="n">view_dependency_assignments_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;view_dependency_assignments&#39;</span><span class="p">)</span>
    <span class="n">view_dependency_assignments_dict</span><span class="p">[</span>
        <span class="s">&#39;view_dependency_assignments_view_dependency&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">view_subset</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">view_subset</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="n">view_subset</span> <span class="o">!=</span> <span class="s">&#39;any&#39;</span><span class="p">):</span>
      <span class="n">view_dependency_assignments_dict</span><span class="p">[</span>
          <span class="s">&#39;view_dependency_assignments_view_dependency&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s">_dep&#39;</span> <span class="o">%</span>
                                                            <span class="n">view_subset</span><span class="p">)</span>
    <span class="n">view_dependency_assignments_dict</span><span class="p">[</span>
        <span class="s">&#39;view_dependency_assignments_view_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">view_superset</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="n">view_assignments</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
          <span class="s">&#39;view_dependency_assignments&#39;</span><span class="p">,</span> <span class="n">view_dependency_assignments_dict</span><span class="p">)</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>

    <span class="n">view_assignments_dict</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="k">for</span> <span class="n">view_assignment</span> <span class="ow">in</span> <span class="n">view_assignments</span><span class="p">:</span>
      <span class="k">if</span><span class="p">(</span> <span class="ow">not</span> <span class="n">view_assignment</span><span class="p">[</span><span class="s">&#39;view_dependency_assignments_view_name&#39;</span><span class="p">]</span> <span class="ow">in</span>
          <span class="n">view_assignments_dict</span> <span class="p">):</span>
        <span class="n">view_assignments_dict</span><span class="p">[</span><span class="n">view_assignment</span><span class="p">[</span>
            <span class="s">&#39;view_dependency_assignments_view_name&#39;</span><span class="p">]]</span> <span class="o">=</span> <span class="p">[]</span>

      <span class="k">if</span><span class="p">(</span> <span class="n">view_assignment</span><span class="p">[</span>
          <span class="s">&#39;view_dependency_assignments_view_dependency&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s">&#39;_dep&#39;</span><span class="p">)</span> <span class="p">):</span>

        <span class="n">view_assignment</span><span class="p">[</span>
            <span class="s">&#39;view_dependency_assignments_view_dependency&#39;</span><span class="p">]</span> <span class="o">=</span>  <span class="n">view_assignment</span><span class="p">[</span>
                <span class="s">&#39;view_dependency_assignments_view_dependency&#39;</span><span class="p">][:</span><span class="o">-</span><span class="mi">4</span><span class="p">:]</span>

      <span class="n">view_assignments_dict</span><span class="p">[</span><span class="n">view_assignment</span><span class="p">[</span>
          <span class="s">&#39;view_dependency_assignments_view_name&#39;</span><span class="p">]]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">view_assignment</span><span class="p">[</span>
              <span class="s">&#39;view_dependency_assignments_view_dependency&#39;</span><span class="p">])</span>

    <span class="k">return</span> <span class="n">view_assignments_dict</span>
</div>
<div class="viewcode-block" id="Core.MakeViewAssignment"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.MakeViewAssignment">[docs]</a>  <span class="k">def</span> <span class="nf">MakeViewAssignment</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">view_superset</span><span class="p">,</span> <span class="n">view_subset</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Assigns a view to view.</span>

<span class="sd">    A view contains zones in that view. However zones can be assigned</span>
<span class="sd">    to another view that is a superset of views. For example</span>
<span class="sd">    an assignment can be made for view_a(view_superset) to also include</span>
<span class="sd">    all of view_b&#39;s(view_subset) zones(and by proxy, records). This</span>
<span class="sd">    prevents having to have duplicate records in each view.</span>

<span class="sd">    Most of the time this will not be needed as there is a special</span>
<span class="sd">    subset included in all views(unless explicitly deleted) called the</span>
<span class="sd">    &#39;any&#39; view. Records in the &#39;any&#39; view will be in all views that</span>
<span class="sd">    have not been explicity changed to remove the &#39;any&#39; view.</span>

<span class="sd">    The &#39;any&#39; view subset is automatically tied to a view when a</span>
<span class="sd">    view is created. Also this is the default view for records</span>
<span class="sd">    and zones(again it can be explicitly changed if needed).</span>

<span class="sd">    Inputs:</span>
<span class="sd">      view_superset: string of view name</span>
<span class="sd">      view_subset: string of view name</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">view_dependency_assignments_dict</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s">&#39;view_dependency_assignments_view_name&#39;</span><span class="p">:</span> <span class="n">view_superset</span><span class="p">,</span>
        <span class="s">&#39;view_dependency_assignments_view_dependency&#39;</span><span class="p">:</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">_dep&#39;</span> <span class="o">%</span> <span class="n">view_subset</span><span class="p">}</span>
    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">MakeRow</span><span class="p">(</span><span class="s">&#39;view_dependency_assignments&#39;</span><span class="p">,</span>
                                 <span class="n">view_dependency_assignments_dict</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Core.RemoveViewAssignment"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.RemoveViewAssignment">[docs]</a>  <span class="k">def</span> <span class="nf">RemoveViewAssignment</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">view_superset</span><span class="p">,</span> <span class="n">view_subset</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Removes a view assignment.</span>

<span class="sd">    For more informaton about view assignments please read the</span>
<span class="sd">    MakeViewAssignment docstring.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      view_superset: string of view name</span>
<span class="sd">      view_subset: string of view name</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">view_dependency_assignments_dict</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s">&#39;view_dependency_assignments_view_name&#39;</span><span class="p">:</span> <span class="n">view_superset</span><span class="p">,</span>
        <span class="s">&#39;view_dependency_assignments_view_dependency&#39;</span><span class="p">:</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">_dep&#39;</span> <span class="o">%</span> <span class="n">view_subset</span><span class="p">}</span>
    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="n">row_count</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">RemoveRow</span><span class="p">(</span><span class="s">&#39;view_dependency_assignments&#39;</span><span class="p">,</span>
                                               <span class="n">view_dependency_assignments_dict</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">row_count</span>
</div>
<div class="viewcode-block" id="Core.ListViewToACLAssignments"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.ListViewToACLAssignments">[docs]</a>  <span class="k">def</span> <span class="nf">ListViewToACLAssignments</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">view_name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">dns_server_set</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                               <span class="n">acl_name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">acl_range_allowed</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Lists some or all view to acl assignments corresponding to the</span>
<span class="sd">    given args.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      view_name: string of view name</span>
<span class="sd">      dns_server_set: string of dns_server_set name</span>
<span class="sd">      acl_name: string of acl name</span>

<span class="sd">    Outputs:</span>
<span class="sd">      list: list contains dictionaries of assignments</span>
<span class="sd">        example: [{&#39;view_name&#39;: &#39;main_view&#39;, &#39;acl_name&#39;: &#39;internal&#39;,</span>
<span class="sd">                   &#39;acl_range_allowed&#39;: &#39;true&#39;},</span>
<span class="sd">                  {&#39;view_name&#39;: &#39;other_view&#39;, &#39;acl_name&#39;: &#39;external&#39;,</span>
<span class="sd">                   &#39;acl_range_allowed&#39;: &#39;false&#39;}]</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="s">&#39;ListViewToACLAssignments&#39;</span><span class="p">)</span>
    <span class="n">view_acl_assign_dict</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s">&#39;view_acl_assignments_acl_name&#39;</span><span class="p">:</span> <span class="n">acl_name</span><span class="p">,</span>
        <span class="s">&#39;view_acl_assignments_dns_server_set_name&#39;</span><span class="p">:</span> <span class="n">dns_server_set</span><span class="p">,</span>
        <span class="s">&#39;view_acl_assignments_view_name&#39;</span><span class="p">:</span> <span class="n">view_name</span><span class="p">,</span>
        <span class="s">&#39;view_acl_assignments_range_allowed&#39;</span><span class="p">:</span> <span class="n">acl_range_allowed</span><span class="p">}</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="n">view_acl_assignments</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;view_acl_assignments&#39;</span><span class="p">,</span>
                                                      <span class="n">view_acl_assign_dict</span><span class="p">)</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>

    <span class="n">assignments_dicts</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">view_acl_assignment</span> <span class="ow">in</span> <span class="n">view_acl_assignments</span><span class="p">:</span>
      <span class="n">assignments_dict</span> <span class="o">=</span> <span class="p">{}</span>
      <span class="n">assignments_dict</span><span class="p">[</span><span class="s">&#39;view_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">view_acl_assignment</span><span class="p">[</span>
          <span class="s">&#39;view_acl_assignments_view_name&#39;</span><span class="p">]</span>
      <span class="n">assignments_dict</span><span class="p">[</span><span class="s">&#39;dns_server_set_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">view_acl_assignment</span><span class="p">[</span>
          <span class="s">&#39;view_acl_assignments_dns_server_set_name&#39;</span><span class="p">]</span>
      <span class="n">assignments_dict</span><span class="p">[</span><span class="s">&#39;acl_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">view_acl_assignment</span><span class="p">[</span>
          <span class="s">&#39;view_acl_assignments_acl_name&#39;</span><span class="p">]</span>
      <span class="n">assignments_dict</span><span class="p">[</span><span class="s">&#39;acl_range_allowed&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">view_acl_assignment</span><span class="p">[</span>
          <span class="s">&#39;view_acl_assignments_range_allowed&#39;</span><span class="p">]</span>
      <span class="n">assignments_dicts</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">assignments_dict</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">assignments_dicts</span>
</div>
<div class="viewcode-block" id="Core.MakeViewToACLAssignments"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.MakeViewToACLAssignments">[docs]</a>  <span class="k">def</span> <span class="nf">MakeViewToACLAssignments</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">view_name</span><span class="p">,</span> <span class="n">dns_server_set_name</span><span class="p">,</span>
                               <span class="n">acl_name</span><span class="p">,</span> <span class="n">acl_range_allowed</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Makes view to acl assignment</span>

<span class="sd">    Inputs:</span>
<span class="sd">      view_name: string of view name</span>
<span class="sd">      dns_server_set_name: string of dns_server_set name</span>
<span class="sd">      acl_name: string of acl name</span>
<span class="sd">      acl_range_allowed: boolean to allow/disallow given acl range</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">view_acl_assign_dict</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s">&#39;view_acl_assignments_acl_name&#39;</span><span class="p">:</span> <span class="n">acl_name</span><span class="p">,</span>
        <span class="s">&#39;view_acl_assignments_dns_server_set_name&#39;</span><span class="p">:</span> <span class="n">dns_server_set_name</span><span class="p">,</span>
        <span class="s">&#39;view_acl_assignments_view_name&#39;</span><span class="p">:</span> <span class="n">view_name</span><span class="p">,</span>
        <span class="s">&#39;view_acl_assignments_range_allowed&#39;</span><span class="p">:</span> <span class="n">acl_range_allowed</span><span class="p">}</span>
    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">MakeRow</span><span class="p">(</span><span class="s">&#39;view_acl_assignments&#39;</span><span class="p">,</span> <span class="n">view_acl_assign_dict</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Core.RemoveViewToACLAssignments"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.RemoveViewToACLAssignments">[docs]</a>  <span class="k">def</span> <span class="nf">RemoveViewToACLAssignments</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">view_name</span><span class="p">,</span> <span class="n">dns_server_set_name</span><span class="p">,</span>
                                 <span class="n">acl_name</span><span class="p">,</span> <span class="n">acl_range_allowed</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Removes view to acl assignment</span>

<span class="sd">    Inputs:</span>
<span class="sd">      view_name: string of view name</span>
<span class="sd">      dns_server_set_name: string of dns_server_set name</span>
<span class="sd">      acl_name: string of acl name</span>

<span class="sd">    Outputs:</span>
<span class="sd">      int: number of rows modified</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">view_acl_assign_dict</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s">&#39;view_acl_assignments_acl_name&#39;</span><span class="p">:</span> <span class="n">acl_name</span><span class="p">,</span>
        <span class="s">&#39;view_acl_assignments_dns_server_set_name&#39;</span><span class="p">:</span> <span class="n">dns_server_set_name</span><span class="p">,</span>
        <span class="s">&#39;view_acl_assignments_view_name&#39;</span><span class="p">:</span> <span class="n">view_name</span><span class="p">,</span>
        <span class="s">&#39;view_acl_assignments_range_allowed&#39;</span><span class="p">:</span> <span class="n">acl_range_allowed</span><span class="p">}</span>
    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="n">row_count</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">RemoveRow</span><span class="p">(</span><span class="s">&#39;view_acl_assignments&#39;</span><span class="p">,</span>
                                               <span class="n">view_acl_assign_dict</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">row_count</span>
</div>
<div class="viewcode-block" id="Core.ListZones"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.ListZones">[docs]</a>  <span class="k">def</span> <span class="nf">ListZones</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">zone_name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">zone_type</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">zone_origin</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                <span class="n">view_name</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Lists zones.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      zone_name: string of zone name</span>
<span class="sd">      zone_type: string of zone type</span>
<span class="sd">      zone_origin: string of zone origin. ex dept.univiersity.edu.</span>
<span class="sd">      view_name: string of view name</span>

<span class="sd">    Outputs:</span>
<span class="sd">      Dictionary of dictionaries. The parent dictionary is keyed by zone name,</span>
<span class="sd">      the secondary dictionary is keyed by view name and the third is keyed</span>
<span class="sd">      by type of data.</span>
<span class="sd">        example:</span>
<span class="sd">          {&#39;zone.university.edu&#39;: {&#39;internal&#39;: {&#39;zone_type&#39;: &#39;master&#39;,</span>
<span class="sd">                                                &#39;zone_options&#39;: &#39;misc opts&#39;,</span>
<span class="sd">                                                &#39;zone_origin&#39;:</span>
<span class="sd">                                                    &#39;university.edu.&#39;},</span>
<span class="sd">                                   &#39;any&#39;: {&#39;zone_type&#39;: &#39;master&#39;</span>
<span class="sd">                                           &#39;zone_options&#39;: &#39;other options&#39;,</span>
<span class="sd">                                           &#39;zone_origin&#39;: &#39;university.edu.&#39;}},</span>
<span class="sd">           &#39;otherzone.university.edu&#39;: {&#39;any&#39;: {&#39;zone_type&#39;: &#39;slave&#39;,</span>
<span class="sd">                                                &#39;zone_options&#39;: &#39;options&#39;}}}</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="s">&#39;ListZones&#39;</span><span class="p">)</span>
    <span class="n">zone_view_assignments_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;zone_view_assignments&#39;</span><span class="p">)</span>

    <span class="k">if</span><span class="p">(</span> <span class="n">view_name</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="n">view_name</span> <span class="o">!=</span> <span class="s">u&#39;any&#39;</span> <span class="p">):</span>
      <span class="n">view_name</span> <span class="o">=</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">_dep&#39;</span> <span class="o">%</span> <span class="n">view_name</span>

    <span class="n">zone_view_assignments_dict</span><span class="p">[</span><span class="s">&#39;zone_view_assignments_zone_name&#39;</span><span class="p">]</span> <span class="o">=</span>  <span class="n">zone_name</span>
    <span class="n">zone_view_assignments_dict</span><span class="p">[</span><span class="s">&#39;zone_view_assignments_zone_type&#39;</span><span class="p">]</span> <span class="o">=</span>  <span class="n">zone_type</span>
    <span class="n">zone_view_assignments_dict</span><span class="p">[</span><span class="s">&#39;zone_origin&#39;</span><span class="p">]</span> <span class="o">=</span>  <span class="n">zone_origin</span>
    <span class="n">zone_view_assignments_dict</span><span class="p">[</span>
        <span class="s">&#39;zone_view_assignments_view_dependency&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">view_name</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="n">zone_view_assignment_rows</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
          <span class="s">&#39;zone_view_assignments&#39;</span><span class="p">,</span> <span class="n">zone_view_assignments_dict</span><span class="p">)</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>

    <span class="n">zone_view_assignments</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="k">for</span> <span class="n">row</span> <span class="ow">in</span> <span class="n">zone_view_assignment_rows</span><span class="p">:</span>
      <span class="k">if</span><span class="p">(</span> <span class="ow">not</span> <span class="n">row</span><span class="p">[</span><span class="s">&#39;zone_view_assignments_zone_name&#39;</span><span class="p">]</span> <span class="ow">in</span> <span class="n">zone_view_assignments</span> <span class="p">):</span>
        <span class="n">zone_view_assignments</span><span class="p">[</span><span class="n">row</span><span class="p">[</span><span class="s">&#39;zone_view_assignments_zone_name&#39;</span><span class="p">]]</span> <span class="o">=</span> <span class="p">{}</span>

      <span class="k">if</span><span class="p">(</span> <span class="ow">not</span> <span class="n">row</span><span class="p">[</span><span class="s">&#39;zone_view_assignments_view_dependency&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">&#39;_dep&#39;</span><span class="p">,</span> <span class="s">&#39;&#39;</span><span class="p">)</span>
          <span class="ow">in</span> <span class="n">zone_view_assignments</span><span class="p">[</span><span class="n">row</span><span class="p">[</span><span class="s">&#39;zone_view_assignments_zone_name&#39;</span><span class="p">]]</span> <span class="p">):</span>
        <span class="n">zone_view_assignments</span><span class="p">[</span><span class="n">row</span><span class="p">[</span><span class="s">&#39;zone_view_assignments_zone_name&#39;</span><span class="p">]][</span>
            <span class="n">row</span><span class="p">[</span><span class="s">&#39;zone_view_assignments_view_dependency&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span>
                <span class="s">&#39;_dep&#39;</span><span class="p">,</span> <span class="s">&#39;&#39;</span><span class="p">)]</span> <span class="o">=</span> <span class="p">{}</span>
      <span class="n">zone_options</span> <span class="o">=</span> <span class="n">iscpy</span><span class="o">.</span><span class="n">Deserialize</span><span class="p">(</span><span class="n">row</span><span class="p">[</span><span class="s">&#39;zone_options&#39;</span><span class="p">])</span>
      <span class="n">zone_view_assignments</span><span class="p">[</span><span class="n">row</span><span class="p">[</span><span class="s">&#39;zone_view_assignments_zone_name&#39;</span><span class="p">]][</span>
          <span class="n">row</span><span class="p">[</span><span class="s">&#39;zone_view_assignments_view_dependency&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">&#39;_dep&#39;</span><span class="p">,</span> <span class="s">&#39;&#39;</span><span class="p">)]</span> <span class="o">=</span> <span class="p">(</span>
              <span class="p">{</span><span class="s">&#39;zone_type&#39;</span><span class="p">:</span> <span class="n">row</span><span class="p">[</span><span class="s">&#39;zone_view_assignments_zone_type&#39;</span><span class="p">],</span>
               <span class="s">&#39;zone_options&#39;</span><span class="p">:</span> <span class="n">zone_options</span><span class="p">,</span>
               <span class="s">&#39;zone_origin&#39;</span><span class="p">:</span> <span class="n">row</span><span class="p">[</span><span class="s">&#39;zone_origin&#39;</span><span class="p">]})</span>

    <span class="k">return</span> <span class="n">zone_view_assignments</span>
</div>
<div class="viewcode-block" id="Core.MakeZone"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.MakeZone">[docs]</a>  <span class="k">def</span> <span class="nf">MakeZone</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">zone_name</span><span class="p">,</span> <span class="n">zone_type</span><span class="p">,</span> <span class="n">zone_origin</span><span class="p">,</span> <span class="n">view_name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
               <span class="n">zone_options</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">make_any</span><span class="o">=</span><span class="bp">True</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Makes a zone.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      zone_name: string of zone name</span>
<span class="sd">      zone_type: string of zone type</span>
<span class="sd">      zone_origin: string of zone origin. ex dept.univiersity.edu.</span>
<span class="sd">      zone_options: string of zone_options(defaults to empty string)</span>
<span class="sd">                    valid zone options can be found here:</span>
<span class="sd">                      http://www.bind9.net/manual/bind/9.3.2/Bv9ARM.ch06.html#zone_statement_grammar</span>
<span class="sd">      view_name: string of view name(defaults to &#39;any&#39;)</span>
<span class="sd">                 see docstring of MakeViewAssignments as to why &#39;any&#39; is default</span>
<span class="sd">      make_any: regardless of view name, make any as well(default to True)</span>

<span class="sd">    Raises:</span>
<span class="sd">      UnexpectedDataError: Invalid zone type.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="k">if</span><span class="p">(</span> <span class="n">zone_options</span> <span class="ow">is</span> <span class="bp">None</span> <span class="p">):</span>
      <span class="n">zone_options</span> <span class="o">=</span> <span class="s">u&#39;&#39;</span>

    <span class="k">if</span><span class="p">(</span> <span class="n">view_name</span> <span class="ow">is</span> <span class="bp">None</span> <span class="p">):</span>
      <span class="n">view_name</span> <span class="o">=</span> <span class="s">u&#39;any&#39;</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="n">view_name</span> <span class="o">=</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">_dep&#39;</span> <span class="o">%</span> <span class="n">view_name</span>

    <span class="n">zone_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;zone_name&#39;</span><span class="p">:</span> <span class="n">zone_name</span><span class="p">}</span>
    <span class="n">zone_view_assignments_dict</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s">&#39;zone_view_assignments_zone_name&#39;</span><span class="p">:</span> <span class="n">zone_name</span><span class="p">,</span>
        <span class="s">&#39;zone_view_assignments_view_dependency&#39;</span><span class="p">:</span> <span class="n">view_name</span><span class="p">,</span>
        <span class="s">&#39;zone_view_assignments_zone_type&#39;</span><span class="p">:</span> <span class="n">zone_type</span><span class="p">,</span>
        <span class="s">&#39;zone_origin&#39;</span><span class="p">:</span> <span class="n">zone_origin</span><span class="p">,</span>
        <span class="s">&#39;zone_options&#39;</span><span class="p">:</span> <span class="n">iscpy</span><span class="o">.</span><span class="n">Serialize</span><span class="p">(</span><span class="n">zone_options</span><span class="p">)}</span>

    <span class="n">search_any_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;zone_view_assignments&#39;</span><span class="p">)</span>
    <span class="n">search_any_dict</span><span class="p">[</span><span class="s">&#39;zone_view_assignments_view_dependency&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s">u&#39;any&#39;</span>
    <span class="n">search_any_dict</span><span class="p">[</span><span class="s">&#39;zone_view_assignments_zone_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">zone_name</span>
    <span class="n">zone_type_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;zone_type&#39;</span><span class="p">:</span> <span class="n">zone_type</span><span class="p">}</span>
    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="k">if</span><span class="p">(</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;zone_types&#39;</span><span class="p">,</span> <span class="n">zone_type_dict</span><span class="p">)</span> <span class="p">):</span>
          <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">UnexpectedDataError</span><span class="p">(</span><span class="s">&#39;Invalid zone type.&#39;</span><span class="p">)</span>
        <span class="k">if</span><span class="p">(</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;zones&#39;</span><span class="p">,</span> <span class="n">zone_dict</span><span class="p">)</span> <span class="p">):</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">MakeRow</span><span class="p">(</span><span class="s">&#39;zones&#39;</span><span class="p">,</span> <span class="n">zone_dict</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">MakeRow</span><span class="p">(</span><span class="s">&#39;zone_view_assignments&#39;</span><span class="p">,</span>
                                 <span class="n">zone_view_assignments_dict</span><span class="p">)</span>
        <span class="k">if</span><span class="p">(</span> <span class="n">view_name</span> <span class="o">!=</span> <span class="s">u&#39;any&#39;</span> <span class="ow">and</span> <span class="n">make_any</span> <span class="p">):</span>
          <span class="k">if</span><span class="p">(</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;zone_view_assignments&#39;</span><span class="p">,</span>
                                           <span class="n">search_any_dict</span><span class="p">)</span> <span class="p">):</span>
            <span class="n">zone_view_assignments_dict</span><span class="p">[</span>
                <span class="s">&#39;zone_view_assignments_view_dependency&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s">u&#39;any&#39;</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">MakeRow</span><span class="p">(</span><span class="s">&#39;zone_view_assignments&#39;</span><span class="p">,</span>
                                     <span class="n">zone_view_assignments_dict</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Core.RemoveZone"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.RemoveZone">[docs]</a>  <span class="k">def</span> <span class="nf">RemoveZone</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">zone_name</span><span class="p">,</span> <span class="n">view_name</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Removes a zone.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      zone_name: string of zone name</span>
<span class="sd">      view_name: string of view name</span>

<span class="sd">    Outputs:</span>
<span class="sd">      int: number of rows affected</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">zone_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;zone_name&#39;</span><span class="p">:</span> <span class="n">zone_name</span><span class="p">}</span>
    <span class="n">zone_view_assignments_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;zone_view_assignments&#39;</span><span class="p">)</span>
    <span class="n">zone_view_assignments_dict</span><span class="p">[</span><span class="s">&#39;zone_view_assignments_zone_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">zone_name</span>

    <span class="n">row_count</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="n">zone_assignments_by_name</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
            <span class="s">&#39;zone_view_assignments&#39;</span><span class="p">,</span> <span class="n">zone_view_assignments_dict</span><span class="p">)</span>
        <span class="k">if</span><span class="p">(</span> <span class="n">view_name</span> <span class="ow">is</span> <span class="bp">None</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">zone_assignments_by_name</span><span class="p">)</span> <span class="o">&lt;=</span> <span class="mi">1</span> <span class="p">):</span>
          <span class="c"># Because of cascading deletes this should remove anything in the</span>
          <span class="c"># zone_view_assignments table as well</span>
          <span class="n">row_count</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">RemoveRow</span><span class="p">(</span><span class="s">&#39;zones&#39;</span><span class="p">,</span> <span class="n">zone_dict</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
          <span class="k">if</span><span class="p">(</span> <span class="n">view_name</span> <span class="o">==</span> <span class="s">&#39;any&#39;</span> <span class="p">):</span>
            <span class="n">zone_view_assignments_dict</span><span class="p">[</span>
                <span class="s">&#39;zone_view_assignments_view_dependency&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">view_name</span>
          <span class="k">else</span><span class="p">:</span>
            <span class="n">zone_view_assignments_dict</span><span class="p">[</span>
                <span class="s">&#39;zone_view_assignments_view_dependency&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">_dep&#39;</span> <span class="o">%</span> <span class="n">view_name</span>
          <span class="c"># Because zone_name/zone_view together are uniquely constrained in</span>
          <span class="c"># this table no need to check if there are more than one.</span>
          <span class="n">found_zone_assignment</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
              <span class="s">&#39;zone_view_assignments&#39;</span><span class="p">,</span> <span class="n">zone_view_assignments_dict</span><span class="p">,</span>
              <span class="n">lock_rows</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
          <span class="k">if</span><span class="p">(</span> <span class="n">found_zone_assignment</span> <span class="p">):</span>
            <span class="n">row_count</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">RemoveRow</span><span class="p">(</span><span class="s">&#39;zone_view_assignments&#39;</span><span class="p">,</span>
                                                    <span class="n">found_zone_assignment</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">row_count</span>
</div>
<div class="viewcode-block" id="Core.UpdateZone"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.UpdateZone">[docs]</a>  <span class="k">def</span> <span class="nf">UpdateZone</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">search_zone_name</span><span class="p">,</span> <span class="n">search_view_name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                 <span class="n">update_zone_name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">update_zone_options</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Updates zone options or zone type of zone</span>

<span class="sd">    Inputs:</span>
<span class="sd">      search_zone_name: string of zone name</span>
<span class="sd">      search_view_name: string of view name</span>
<span class="sd">      update_zone_name: string of zone name</span>
<span class="sd">      update_zone_options: string of zone options</span>
<span class="sd">                           valid zone options can be found here:</span>
<span class="sd">                             http://www.bind9.net/manual/bind/9.3.2/Bv9ARM.ch06.html#zone_statement_grammar</span>

<span class="sd">    Outputs:</span>
<span class="sd">      int: number of rows affected</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="k">if</span><span class="p">(</span> <span class="n">search_view_name</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="n">search_view_name</span> <span class="o">!=</span> <span class="s">u&#39;any&#39;</span> <span class="p">):</span>
      <span class="n">search_view_name</span> <span class="o">=</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">_dep&#39;</span> <span class="o">%</span> <span class="n">search_view_name</span>

    <span class="n">search_zone_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;zone_name&#39;</span><span class="p">:</span> <span class="n">search_zone_name</span><span class="p">}</span>
    <span class="n">update_zone_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;zone_name&#39;</span><span class="p">:</span> <span class="n">update_zone_name</span><span class="p">}</span>

    <span class="n">search_zone_view_assignments_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;zone_view_assignments&#39;</span><span class="p">)</span>
    <span class="n">search_zone_view_assignments_dict</span><span class="p">[</span><span class="s">&#39;zone_view_assignments_zone_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
        <span class="n">search_zone_name</span><span class="p">)</span>
    <span class="n">search_zone_view_assignments_dict</span><span class="p">[</span>
        <span class="s">&#39;zone_view_assignments_view_dependency&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">search_view_name</span>

    <span class="n">update_zone_view_assignments_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;zone_view_assignments&#39;</span><span class="p">)</span>
    <span class="n">update_zone_view_assignments_dict</span><span class="p">[</span><span class="s">&#39;zone_view_assignments_zone_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
        <span class="n">update_zone_name</span><span class="p">)</span>
    <span class="n">update_zone_view_assignments_dict</span><span class="p">[</span><span class="s">&#39;zone_options&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">iscpy</span><span class="o">.</span><span class="n">Serialize</span><span class="p">(</span><span class="n">update_zone_options</span><span class="p">)</span>

    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="n">row_count</span> <span class="o">=</span> <span class="mi">0</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="k">if</span><span class="p">(</span> <span class="n">update_zone_name</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="n">search_view_name</span> <span class="ow">is</span> <span class="bp">None</span> <span class="p">):</span>
          <span class="n">row_count</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">UpdateRow</span><span class="p">(</span><span class="s">&#39;zones&#39;</span><span class="p">,</span> <span class="n">search_zone_dict</span><span class="p">,</span>
                                                  <span class="n">update_zone_dict</span><span class="p">)</span>
        <span class="n">row_count</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">UpdateRow</span><span class="p">(</span>
            <span class="s">&#39;zone_view_assignments&#39;</span><span class="p">,</span><span class="n">search_zone_view_assignments_dict</span><span class="p">,</span>
            <span class="n">update_zone_view_assignments_dict</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">row_count</span>
</div>
<div class="viewcode-block" id="Core.ListReverseRangeZoneAssignments"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.ListReverseRangeZoneAssignments">[docs]</a>  <span class="k">def</span> <span class="nf">ListReverseRangeZoneAssignments</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">zone_name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">cidr_block</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Lists reverse range to zone assignments.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      zone_name: string of zone name</span>
<span class="sd">      cidr_block: string of cidr block</span>

<span class="sd">    Outputs:</span>
<span class="sd">      dictionary: keyed by zone_name with values of cidr blocks</span>
<span class="sd">        example: {&#39;10.in-addr.arpa&#39;: &#39;10/8&#39;,</span>
<span class="sd">                  &#39;9.168.192.in-addr.arpa&#39;: &#39;192.168.9/24&#39;}</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="s">&#39;ListReverseRangeZoneAssignments&#39;</span><span class="p">)</span>
    <span class="n">assignment_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;reverse_range_zone_assignments_zone_name&#39;</span><span class="p">:</span> <span class="n">zone_name</span><span class="p">,</span>
                       <span class="s">&#39;reverse_range_zone_assignments_cidr_block&#39;</span><span class="p">:</span> <span class="n">cidr_block</span><span class="p">}</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="n">assignment_rows</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
          <span class="s">&#39;reverse_range_zone_assignments&#39;</span><span class="p">,</span> <span class="n">assignment_dict</span><span class="p">)</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>

    <span class="n">reverse_range_dict</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="k">for</span> <span class="n">row</span> <span class="ow">in</span> <span class="n">assignment_rows</span><span class="p">:</span>
      <span class="n">reverse_range_dict</span><span class="p">[</span><span class="n">row</span><span class="p">[</span><span class="s">&#39;reverse_range_zone_assignments_zone_name&#39;</span><span class="p">]]</span> <span class="o">=</span> <span class="p">(</span>
          <span class="n">row</span><span class="p">[</span><span class="s">&#39;reverse_range_zone_assignments_cidr_block&#39;</span><span class="p">])</span>

    <span class="k">return</span> <span class="n">reverse_range_dict</span>
</div>
<div class="viewcode-block" id="Core.MakeReverseRangeZoneAssignment"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.MakeReverseRangeZoneAssignment">[docs]</a>  <span class="k">def</span> <span class="nf">MakeReverseRangeZoneAssignment</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">zone_name</span><span class="p">,</span> <span class="n">cidr_block</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Makes a reverse range to zone assignment.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      zone_name: string of zone name</span>
<span class="sd">      cidr_block: string of cidr block</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">assignment_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;reverse_range_zone_assignments_zone_name&#39;</span><span class="p">:</span> <span class="n">zone_name</span><span class="p">,</span>
                       <span class="s">&#39;reverse_range_zone_assignments_cidr_block&#39;</span><span class="p">:</span> <span class="n">cidr_block</span><span class="p">}</span>
    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">MakeRow</span><span class="p">(</span><span class="s">&#39;reverse_range_zone_assignments&#39;</span><span class="p">,</span>
                                 <span class="n">assignment_dict</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>

</div>
<div class="viewcode-block" id="Core.RemoveReverseRangeZoneAssignment"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.RemoveReverseRangeZoneAssignment">[docs]</a>  <span class="k">def</span> <span class="nf">RemoveReverseRangeZoneAssignment</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">zone_name</span><span class="p">,</span> <span class="n">cidr_block</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Remove reverse range to zone assignment.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      zone_name: string of zone name</span>
<span class="sd">      cidr_block: string of cidr block</span>

<span class="sd">    Outputs:</span>
<span class="sd">      int: number of rows affected</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">assignment_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;reverse_range_zone_assignments_zone_name&#39;</span><span class="p">:</span> <span class="n">zone_name</span><span class="p">,</span>
                       <span class="s">&#39;reverse_range_zone_assignments_cidr_block&#39;</span><span class="p">:</span> <span class="n">cidr_block</span><span class="p">}</span>
    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="n">row_count</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">RemoveRow</span><span class="p">(</span><span class="s">&#39;reverse_range_zone_assignments&#39;</span><span class="p">,</span>
                                               <span class="n">assignment_dict</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">row_count</span>
</div>
<div class="viewcode-block" id="Core.ListForwardZonePermissions"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.ListForwardZonePermissions">[docs]</a>  <span class="k">def</span> <span class="nf">ListForwardZonePermissions</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">zone_name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">group_name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                                 <span class="n">group_permission</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;List forward zone permissions.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      zone_name: string of zone name</span>
<span class="sd">      group_name: string of group name</span>
<span class="sd">      group_permission: list group permissions, i.e., [&#39;a&#39;, &#39;aaaa&#39;, &#39;cname&#39;]</span>

<span class="sd">    Outputs:</span>
<span class="sd">      dictionary keyed by group name with values of lists of dictionaries</span>
<span class="sd">      containing zone names and group permissions</span>
<span class="sd">        example: {&#39;dept&#39;: [{&#39;zone_name&#39;: &#39;sub.univeristy.edu&#39;,</span>
<span class="sd">                            &#39;group_permission&#39;: [&#39;a&#39;, &#39;aaaa&#39;, &#39;cname&#39;]},</span>
<span class="sd">                           {&#39;zone_name&#39;: &#39;othersub.university.edu&#39;,</span>
<span class="sd">                            &#39;group_permission&#39;: [&#39;a&#39;, &#39;aaaa&#39;, &#39;cname&#39;, &#39;soa&#39;]}],</span>
<span class="sd">                  &#39;otherdept&#39;: [{&#39;zone_name&#39;: &#39;sub.university.edu&#39;,</span>
<span class="sd">                                 &#39;group_permission&#39;: [&#39;a&#39;, &#39;aaaa&#39;]}]}</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">forward_zone_permissions_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;forward_zone_permissions&#39;</span><span class="p">)</span>
    <span class="n">forward_zone_permissions_dict</span><span class="p">[</span><span class="s">&#39;forward_zone_permissions_group_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
        <span class="n">group_name</span><span class="p">)</span>
    <span class="n">forward_zone_permissions_dict</span><span class="p">[</span><span class="s">&#39;forward_zone_permissions_zone_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
        <span class="n">zone_name</span><span class="p">)</span>

    <span class="n">group_forward_permissions_dicts</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">forward_zone_permissions_rows</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">group_forward_permissions_rows_dict</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="n">group_forward_permissions</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="n">forward_zone_permissions_rows</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
            <span class="s">&#39;forward_zone_permissions&#39;</span><span class="p">,</span> <span class="n">forward_zone_permissions_dict</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">row</span> <span class="ow">in</span> <span class="n">forward_zone_permissions_rows</span><span class="p">:</span>
          <span class="n">group_forward_permissions_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
              <span class="s">&#39;group_forward_permissions&#39;</span><span class="p">)</span>
          <span class="n">group_forward_permissions_dict</span><span class="p">[</span>
              <span class="s">&#39;group_forward_permissions_forward_zone_permissions_id&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">row</span><span class="p">[</span>
                  <span class="s">&#39;forward_zone_permissions_id&#39;</span><span class="p">]</span>
          <span class="n">group_permissions_row_permission_list</span> <span class="o">=</span> <span class="p">[]</span>
          <span class="k">for</span> <span class="n">group_permissions_row</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
                  <span class="s">&#39;group_forward_permissions&#39;</span><span class="p">,</span>
                  <span class="n">group_forward_permissions_dict</span><span class="p">):</span>
            <span class="n">group_permissions_row_permission_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">group_permissions_row</span><span class="p">[</span>
                <span class="s">&#39;group_forward_permissions_group_permission&#39;</span><span class="p">])</span>
          <span class="k">if</span><span class="p">(</span> <span class="n">group_permission</span> <span class="ow">is</span> <span class="bp">None</span> <span class="ow">or</span> <span class="n">group_permission</span> <span class="o">==</span> <span class="p">(</span>
                  <span class="n">group_permissions_row_permission_list</span><span class="p">)</span> <span class="p">):</span>
            <span class="n">group_forward_permissions_rows_dict</span><span class="o">.</span><span class="n">update</span><span class="p">({</span>
                <span class="nb">str</span><span class="p">(</span><span class="n">row</span><span class="p">[</span><span class="s">&#39;forward_zone_permissions_id&#39;</span><span class="p">]):</span> <span class="p">(</span>
                    <span class="n">group_permissions_row_permission_list</span><span class="p">)})</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>

    <span class="c">## Construct dict to return</span>
    <span class="n">forward_zone_perms_dict</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="k">for</span> <span class="n">row</span> <span class="ow">in</span> <span class="n">forward_zone_permissions_rows</span><span class="p">:</span>
      <span class="k">if</span><span class="p">(</span> <span class="nb">str</span><span class="p">(</span><span class="n">row</span><span class="p">[</span><span class="s">&#39;forward_zone_permissions_id&#39;</span><span class="p">])</span> <span class="ow">in</span> <span class="p">(</span>
              <span class="n">group_forward_permissions_rows_dict</span><span class="p">)</span> <span class="p">):</span>
        <span class="k">if</span><span class="p">(</span> <span class="n">row</span><span class="p">[</span><span class="s">&#39;forward_zone_permissions_group_name&#39;</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span>
                <span class="n">forward_zone_perms_dict</span> <span class="p">):</span>
          <span class="n">forward_zone_perms_dict</span><span class="p">[</span>
              <span class="n">row</span><span class="p">[</span><span class="s">&#39;forward_zone_permissions_group_name&#39;</span><span class="p">]]</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="n">forward_zone_perms_dict</span><span class="p">[</span>
            <span class="n">row</span><span class="p">[</span><span class="s">&#39;forward_zone_permissions_group_name&#39;</span><span class="p">]]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                <span class="p">{</span><span class="s">&#39;zone_name&#39;</span><span class="p">:</span> <span class="n">row</span><span class="p">[</span><span class="s">&#39;forward_zone_permissions_zone_name&#39;</span><span class="p">],</span>
                 <span class="s">&#39;group_permission&#39;</span><span class="p">:</span> <span class="n">group_forward_permissions_rows_dict</span><span class="p">[</span>
                     <span class="nb">str</span><span class="p">(</span><span class="n">row</span><span class="p">[</span><span class="s">&#39;forward_zone_permissions_id&#39;</span><span class="p">])]})</span>

    <span class="k">return</span> <span class="n">forward_zone_perms_dict</span>
</div>
<div class="viewcode-block" id="Core.MakeForwardZonePermission"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.MakeForwardZonePermission">[docs]</a>  <span class="k">def</span> <span class="nf">MakeForwardZonePermission</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">zone_name</span><span class="p">,</span> <span class="n">group_name</span><span class="p">,</span>
                                <span class="n">group_permission</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Make forward zone permission.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      zone_name: string of zone name</span>
<span class="sd">      group_name: string of group name</span>
<span class="sd">      group_permission: list group permissions, i.e., [&#39;a&#39;, &#39;aaaa&#39;, &#39;cname&#39;]</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">forward_zone_permissions_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;forward_zone_permissions&#39;</span><span class="p">)</span>
    <span class="n">forward_zone_permissions_dict</span><span class="p">[</span><span class="s">&#39;forward_zone_permissions_group_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
        <span class="n">group_name</span><span class="p">)</span>
    <span class="n">forward_zone_permissions_dict</span><span class="p">[</span><span class="s">&#39;forward_zone_permissions_zone_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
        <span class="n">zone_name</span><span class="p">)</span>

    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="n">forward_zone_perm_id</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">MakeRow</span><span class="p">(</span>
            <span class="s">&#39;forward_zone_permissions&#39;</span><span class="p">,</span> <span class="n">forward_zone_permissions_dict</span><span class="p">)</span>

        <span class="c">## Add associated group_forward_permissions</span>
        <span class="k">for</span> <span class="n">group_perm</span> <span class="ow">in</span> <span class="n">group_permission</span><span class="p">:</span>
          <span class="n">group_forward_permissions_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
              <span class="s">&#39;group_forward_permissions&#39;</span><span class="p">)</span>
          <span class="n">group_forward_permissions_dict</span><span class="p">[</span>
              <span class="s">&#39;group_forward_permissions_forward_zone_permissions_id&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
                  <span class="n">forward_zone_perm_id</span><span class="p">)</span>
          <span class="n">group_forward_permissions_dict</span><span class="p">[</span>
              <span class="s">&#39;group_forward_permissions_group_permission&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
                  <span class="n">group_perm</span><span class="p">)</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">MakeRow</span><span class="p">(</span><span class="s">&#39;group_forward_permissions&#39;</span><span class="p">,</span>
                                   <span class="n">group_forward_permissions_dict</span><span class="p">)</span>

      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
      <span class="k">if</span><span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">parent_server_instance</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">parent_server_instance</span><span class="o">.</span><span class="n">SetCoreCacheDirty</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="Core.UpdateGroupForwardPermission"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.UpdateGroupForwardPermission">[docs]</a>  <span class="k">def</span> <span class="nf">UpdateGroupForwardPermission</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">zone_name</span><span class="p">,</span> <span class="n">group_name</span><span class="p">,</span> 
                                   <span class="n">new_permissions</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Updates forward zone group permissions</span>

<span class="sd">    Inputs:</span>
<span class="sd">      zone_name: string of zone name</span>
<span class="sd">      group_name: string of group name</span>
<span class="sd">      new_permissions: list of permissions. (ex [u&#39;a&#39;, u&#39;aaaa&#39;, u&#39;cname&#39;])</span>

<span class="sd">    Raises:</span>
<span class="sd">      AuthorizationError: Group does not have access to supplied zone</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">forward_zone_permissions</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ListForwardZonePermissions</span><span class="p">(</span><span class="n">zone_name</span><span class="p">,</span> 
                                                               <span class="n">group_name</span><span class="p">)</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">group_name</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">forward_zone_permissions</span> <span class="p">):</span>
      <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">AuthorizationError</span><span class="p">(</span><span class="s">&#39;Trying to update permissions on zone &#39;</span>
                                      <span class="s">&#39;</span><span class="si">%s</span><span class="s"> not assigned to group </span><span class="si">%s</span><span class="s">.&#39;</span> <span class="o">%</span> <span class="p">(</span>
                                      <span class="n">zone_name</span><span class="p">,</span> <span class="n">group_name</span><span class="p">))</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="n">current_permissions</span> <span class="o">=</span> <span class="n">forward_zone_permissions</span><span class="p">[</span><span class="n">group_name</span><span class="p">]</span>
      <span class="k">for</span> <span class="n">permission</span> <span class="ow">in</span> <span class="n">current_permissions</span><span class="p">:</span>
        <span class="k">if</span><span class="p">(</span> <span class="n">permission</span><span class="p">[</span><span class="s">&#39;zone_name&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="n">zone_name</span> <span class="p">):</span>
          <span class="n">current_permissions</span> <span class="o">=</span> <span class="n">permission</span><span class="p">[</span><span class="s">&#39;group_permission&#39;</span><span class="p">]</span>
          <span class="k">break</span>
      <span class="k">else</span><span class="p">:</span>
        <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">AuthorizationError</span><span class="p">(</span><span class="s">&#39;Trying to update permissions on zone &#39;</span>
                                        <span class="s">&#39;</span><span class="si">%s</span><span class="s"> not assigned to group </span><span class="si">%s</span><span class="s">.&#39;</span> <span class="o">%</span> <span class="p">(</span>
                                        <span class="n">zone_name</span><span class="p">,</span> <span class="n">group_name</span><span class="p">))</span>

    <span class="n">add_permissions</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">set</span><span class="p">(</span><span class="n">new_permissions</span><span class="p">)</span><span class="o">.</span><span class="n">difference</span><span class="p">(</span><span class="nb">set</span><span class="p">(</span>
        <span class="n">current_permissions</span><span class="p">)))</span>
    <span class="n">remove_permissions</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">set</span><span class="p">(</span><span class="n">current_permissions</span><span class="p">)</span><span class="o">.</span><span class="n">difference</span><span class="p">(</span><span class="nb">set</span><span class="p">(</span>
        <span class="n">new_permissions</span><span class="p">)))</span>

    <span class="n">forward_zone_permissions_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;forward_zone_permissions&#39;</span><span class="p">)</span>
    <span class="n">group_forward_permissions_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;group_forward_permissions&#39;</span><span class="p">)</span>

    <span class="n">forward_zone_permissions_dict</span><span class="p">[</span>
        <span class="s">&#39;forward_zone_permissions_group_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">group_name</span>
    <span class="n">forward_zone_permissions_dict</span><span class="p">[</span>
        <span class="s">&#39;forward_zone_permissions_zone_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">zone_name</span>

    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>       
        <span class="n">forward_zone_permissions_row</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
            <span class="s">&#39;forward_zone_permissions&#39;</span><span class="p">,</span> <span class="n">forward_zone_permissions_dict</span><span class="p">)</span>

        <span class="nb">id</span> <span class="o">=</span> <span class="n">forward_zone_permissions_row</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s">&#39;forward_zone_permissions_id&#39;</span><span class="p">]</span>
        <span class="n">group_forward_permissions_dict</span><span class="p">[</span>
            <span class="s">&#39;group_forward_permissions_forward_zone_permissions_id&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">id</span>

        <span class="k">for</span> <span class="n">permission</span> <span class="ow">in</span> <span class="n">remove_permissions</span><span class="p">:</span>
          <span class="n">group_forward_permissions_dict</span><span class="p">[</span>
              <span class="s">&#39;group_forward_permissions_group_permission&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">permission</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">RemoveRow</span><span class="p">(</span><span class="s">&#39;group_forward_permissions&#39;</span><span class="p">,</span>
                                     <span class="n">group_forward_permissions_dict</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">permission</span> <span class="ow">in</span> <span class="n">add_permissions</span><span class="p">:</span>
          <span class="n">group_forward_permissions_dict</span><span class="p">[</span>
              <span class="s">&#39;group_forward_permissions_group_permission&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">permission</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">MakeRow</span><span class="p">(</span><span class="s">&#39;group_forward_permissions&#39;</span><span class="p">,</span>
                                     <span class="n">group_forward_permissions_dict</span><span class="p">)</span>
  
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
      <span class="k">if</span><span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">parent_server_instance</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">parent_server_instance</span><span class="o">.</span><span class="n">SetCoreCacheDirty</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="Core.RemoveForwardZonePermission"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.RemoveForwardZonePermission">[docs]</a>  <span class="k">def</span> <span class="nf">RemoveForwardZonePermission</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">zone_name</span><span class="p">,</span> <span class="n">group_name</span><span class="p">,</span>
                                  <span class="n">group_permission</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Remove forward zone permissions.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      zone_name: string of zone name</span>
<span class="sd">      group_name: string of group name</span>
<span class="sd">      group_permission: list of group permissions, i.e., [&#39;a&#39;, &#39;aaaa&#39;, &#39;cname&#39;]</span>

<span class="sd">    Outputs:</span>
<span class="sd">      int: number of rows affected</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">forward_zone_permissions_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;forward_zone_permissions&#39;</span><span class="p">)</span>
    <span class="n">forward_zone_permissions_dict</span><span class="p">[</span><span class="s">&#39;forward_zone_permissions_group_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
        <span class="n">group_name</span><span class="p">)</span>
    <span class="n">forward_zone_permissions_dict</span><span class="p">[</span><span class="s">&#39;forward_zone_permissions_zone_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
        <span class="n">zone_name</span><span class="p">)</span>

    <span class="n">row_count</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="n">group_forward_permissions_rows</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">forward_zone_permissions_rows</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
            <span class="s">&#39;forward_zone_permissions&#39;</span><span class="p">,</span> <span class="n">forward_zone_permissions_dict</span><span class="p">)</span>
        <span class="k">if</span><span class="p">(</span> <span class="nb">len</span><span class="p">(</span><span class="n">forward_zone_permissions_rows</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span> <span class="p">):</span>
          <span class="k">for</span> <span class="n">permission</span> <span class="ow">in</span> <span class="n">group_permission</span><span class="p">:</span>
            <span class="n">group_forward_permissions_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
                <span class="s">&#39;group_forward_permissions&#39;</span><span class="p">)</span>
            <span class="n">group_forward_permissions_dict</span><span class="p">[</span>
                <span class="s">&#39;group_forward_permissions_group_permission&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">permission</span>
            <span class="n">group_forward_permissions_rows</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
                <span class="s">&#39;group_forward_permissions&#39;</span><span class="p">,</span>
                <span class="n">group_forward_permissions_dict</span><span class="p">))</span>

        <span class="k">for</span> <span class="n">row</span> <span class="ow">in</span> <span class="n">forward_zone_permissions_rows</span><span class="p">:</span>
          <span class="n">forward_zone_permissions_dict</span><span class="p">[</span><span class="s">&#39;forward_zone_permissions_id&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">row</span><span class="p">[</span>
              <span class="s">&#39;forward_zone_permissions_id&#39;</span><span class="p">]</span>
          <span class="n">group_forward_permissions_list</span> <span class="o">=</span> <span class="p">[]</span>

          <span class="k">if</span><span class="p">(</span> <span class="n">group_permission</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="p">):</span>
            <span class="k">for</span> <span class="n">permission</span> <span class="ow">in</span> <span class="n">group_permission</span><span class="p">:</span>
              <span class="n">group_forward_permissions_dict</span> <span class="o">=</span> <span class="p">{</span>
                  <span class="s">&#39;group_forward_permissions_forward_zone_permissions_id&#39;</span><span class="p">:</span> <span class="p">(</span>
                      <span class="n">row</span><span class="p">[</span><span class="s">&#39;forward_zone_permissions_id&#39;</span><span class="p">]),</span>
                  <span class="s">&#39;group_forward_permissions_group_permission&#39;</span><span class="p">:</span> <span class="n">permission</span><span class="p">}</span>
              <span class="n">group_forward_permissions_rows</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
                  <span class="s">&#39;group_forward_permissions&#39;</span><span class="p">,</span>
                  <span class="n">group_forward_permissions_dict</span><span class="p">)</span>
              <span class="k">for</span> <span class="n">group_forward_permissions_row</span> <span class="ow">in</span> <span class="p">(</span>
                      <span class="n">group_forward_permissions_rows</span><span class="p">):</span>
                <span class="n">group_forward_permissions_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                    <span class="n">group_forward_permissions_row</span><span class="p">[</span>
                        <span class="s">&#39;group_forward_permissions_group_permission&#39;</span><span class="p">])</span>
              <span class="k">if</span><span class="p">(</span> <span class="n">group_permission</span> <span class="o">==</span> <span class="n">group_forward_permissions_list</span> <span class="p">):</span>
                <span class="n">row_count</span> <span class="o">=</span> <span class="n">row_count</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">RemoveRow</span><span class="p">(</span>
                    <span class="s">&#39;forward_zone_permissions&#39;</span><span class="p">,</span> <span class="n">forward_zone_permissions_dict</span><span class="p">)</span>
          <span class="k">else</span><span class="p">:</span>
            <span class="n">row_count</span> <span class="o">=</span> <span class="n">row_count</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">RemoveRow</span><span class="p">(</span>
                <span class="s">&#39;forward_zone_permissions&#39;</span><span class="p">,</span> <span class="n">forward_zone_permissions_dict</span><span class="p">)</span>
 	  <span class="c">## Associated group_forward_permissions deleted by CASCADE in DB</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
      <span class="k">if</span><span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">parent_server_instance</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">parent_server_instance</span><span class="o">.</span><span class="n">SetCoreCacheDirty</span><span class="p">()</span>

    <span class="k">return</span> <span class="n">row_count</span>
</div>
<div class="viewcode-block" id="Core.ListReverseRangePermissions"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.ListReverseRangePermissions">[docs]</a>  <span class="k">def</span> <span class="nf">ListReverseRangePermissions</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cidr_block</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">group_name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                                  <span class="n">group_permission</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;List reverse range permissions.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      cidr_block: string of cidr block</span>
<span class="sd">      group_name: string of group name</span>
<span class="sd">      group_permission: list group permissions, i.e., [&#39;a&#39;, &#39;aaaa&#39;, &#39;cname&#39;]</span>

<span class="sd">    Outputs:</span>
<span class="sd">      dictionary keyed by group name with values of lists of dictionaries</span>
<span class="sd">      containing reverse ranges and group permissions</span>
<span class="sd">        example: {&#39;dept&#39;: [{&#39;cidr_block&#39;: &#39;192.168.0/24&#39;,</span>
<span class="sd">                            &#39;group_permission&#39;: [u&#39;cname&#39;, u&#39;ptr&#39;]},</span>
<span class="sd">                           {&#39;cidr_block&#39;: &#39;192.168.1/24&#39;,</span>
<span class="sd">                            &#39;group_permission&#39;: [u&#39;ptr&#39;]}],</span>
<span class="sd">                  &#39;otherdept&#39;: [{&#39;cidr_block&#39;: &#39;192.168.1/24&#39;,</span>
<span class="sd">                                 &#39;group_permission&#39;: [u&#39;cname&#39;, u&#39;ns&#39;, u&#39;ptr&#39;,</span>
<span class="sd">                                                      u&#39;soa&#39;]}]}</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">reverse_range_permissions_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;reverse_range_permissions&#39;</span><span class="p">)</span>
    <span class="n">reverse_range_permissions_dict</span><span class="p">[</span><span class="s">&#39;reverse_range_permissions_group_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
        <span class="n">group_name</span><span class="p">)</span>
    <span class="n">reverse_range_permissions_dict</span><span class="p">[</span><span class="s">&#39;reverse_range_permissions_cidr_block&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
        <span class="n">cidr_block</span><span class="p">)</span>

    <span class="n">group_reverse_permissions_dicts</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">reverse_range_permissions_rows</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">group_reverse_permissions_rows_dict</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="n">group_reverse_permissions</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="n">reverse_range_permissions_rows</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
            <span class="s">&#39;reverse_range_permissions&#39;</span><span class="p">,</span> <span class="n">reverse_range_permissions_dict</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">row</span> <span class="ow">in</span> <span class="n">reverse_range_permissions_rows</span><span class="p">:</span>
          <span class="n">group_reverse_permissions_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
              <span class="s">&#39;group_reverse_permissions&#39;</span><span class="p">)</span>
          <span class="n">group_reverse_permissions_dict</span><span class="p">[</span>
              <span class="s">&#39;group_reverse_permissions_reverse_range_permissions_id&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">row</span><span class="p">[</span>
                  <span class="s">&#39;reverse_range_permissions_id&#39;</span><span class="p">]</span>
          <span class="n">group_permissions_row_permission_list</span> <span class="o">=</span> <span class="p">[]</span>
          <span class="k">for</span> <span class="n">group_permissions_row</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
                  <span class="s">&#39;group_reverse_permissions&#39;</span><span class="p">,</span>
                  <span class="n">group_reverse_permissions_dict</span><span class="p">):</span>
            <span class="n">group_permissions_row_permission_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">group_permissions_row</span><span class="p">[</span>
                <span class="s">&#39;group_reverse_permissions_group_permission&#39;</span><span class="p">])</span>
          <span class="k">if</span><span class="p">(</span> <span class="n">group_permission</span> <span class="ow">is</span> <span class="bp">None</span> <span class="ow">or</span> <span class="n">group_permission</span> <span class="o">==</span> <span class="p">(</span>
                  <span class="n">group_permissions_row_permission_list</span><span class="p">)</span> <span class="p">):</span>
            <span class="n">group_reverse_permissions_rows_dict</span><span class="o">.</span><span class="n">update</span><span class="p">({</span>
                <span class="nb">str</span><span class="p">(</span><span class="n">row</span><span class="p">[</span><span class="s">&#39;reverse_range_permissions_id&#39;</span><span class="p">]):</span> <span class="p">(</span>
                    <span class="n">group_permissions_row_permission_list</span><span class="p">)})</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
      <span class="k">if</span><span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">parent_server_instance</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">parent_server_instance</span><span class="o">.</span><span class="n">SetCoreCacheDirty</span><span class="p">()</span>

    <span class="c">## Construct dict to return</span>
    <span class="n">reverse_range_perms_dict</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="k">for</span> <span class="n">row</span> <span class="ow">in</span> <span class="n">reverse_range_permissions_rows</span><span class="p">:</span>
      <span class="k">if</span><span class="p">(</span> <span class="nb">str</span><span class="p">(</span><span class="n">row</span><span class="p">[</span><span class="s">&#39;reverse_range_permissions_id&#39;</span><span class="p">])</span> <span class="ow">in</span> <span class="p">(</span>
              <span class="n">group_reverse_permissions_rows_dict</span><span class="p">)</span> <span class="p">):</span>
        <span class="k">if</span><span class="p">(</span> <span class="n">row</span><span class="p">[</span><span class="s">&#39;reverse_range_permissions_group_name&#39;</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span>
                <span class="n">reverse_range_perms_dict</span> <span class="p">):</span>
          <span class="n">reverse_range_perms_dict</span><span class="p">[</span>
              <span class="n">row</span><span class="p">[</span><span class="s">&#39;reverse_range_permissions_group_name&#39;</span><span class="p">]]</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="n">reverse_range_perms_dict</span><span class="p">[</span>
            <span class="n">row</span><span class="p">[</span><span class="s">&#39;reverse_range_permissions_group_name&#39;</span><span class="p">]]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                <span class="p">{</span><span class="s">&#39;cidr_block&#39;</span><span class="p">:</span> <span class="n">row</span><span class="p">[</span><span class="s">&#39;reverse_range_permissions_cidr_block&#39;</span><span class="p">],</span>
                 <span class="s">&#39;group_permission&#39;</span><span class="p">:</span> <span class="n">group_reverse_permissions_rows_dict</span><span class="p">[</span>
                     <span class="nb">str</span><span class="p">(</span><span class="n">row</span><span class="p">[</span><span class="s">&#39;reverse_range_permissions_id&#39;</span><span class="p">])]})</span>

    <span class="k">return</span> <span class="n">reverse_range_perms_dict</span>
</div>
<div class="viewcode-block" id="Core.MakeReverseRangePermission"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.MakeReverseRangePermission">[docs]</a>  <span class="k">def</span> <span class="nf">MakeReverseRangePermission</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cidr_block</span><span class="p">,</span> <span class="n">group_name</span><span class="p">,</span>
                                 <span class="n">group_permission</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Make reverse range permission.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      cidr_block: string of cidr block</span>
<span class="sd">      group_name: string of group name</span>
<span class="sd">      group_permission: list of group permissions, i.e., [&#39;cname&#39;, &#39;ptr&#39;]</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">reverse_range_permissions_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;reverse_range_permissions&#39;</span><span class="p">)</span>
    <span class="n">reverse_range_permissions_dict</span><span class="p">[</span><span class="s">&#39;reverse_range_permissions_group_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
        <span class="n">group_name</span><span class="p">)</span>
    <span class="n">reverse_range_permissions_dict</span><span class="p">[</span><span class="s">&#39;reverse_range_permissions_cidr_block&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
        <span class="n">cidr_block</span><span class="p">)</span>

    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="n">reverse_range_perm_id</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">MakeRow</span><span class="p">(</span>
            <span class="s">&#39;reverse_range_permissions&#39;</span><span class="p">,</span> <span class="n">reverse_range_permissions_dict</span><span class="p">)</span>

        <span class="c">## Add associated group_forward_permissions</span>
        <span class="k">for</span> <span class="n">group_perm</span> <span class="ow">in</span> <span class="n">group_permission</span><span class="p">:</span>
          <span class="n">group_reverse_permissions_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
              <span class="s">&#39;group_reverse_permissions&#39;</span><span class="p">)</span>
          <span class="n">group_reverse_permissions_dict</span><span class="p">[</span>
              <span class="s">&#39;group_reverse_permissions_reverse_range_permissions_id&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
                  <span class="n">reverse_range_perm_id</span><span class="p">)</span>
          <span class="n">group_reverse_permissions_dict</span><span class="p">[</span>
              <span class="s">&#39;group_reverse_permissions_group_permission&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
                  <span class="n">group_perm</span><span class="p">)</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">MakeRow</span><span class="p">(</span><span class="s">&#39;group_reverse_permissions&#39;</span><span class="p">,</span>
                                   <span class="n">group_reverse_permissions_dict</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
      <span class="k">if</span><span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">parent_server_instance</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">parent_server_instance</span><span class="o">.</span><span class="n">SetCoreCacheDirty</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="Core.UpdateGroupReversePermission"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.UpdateGroupReversePermission">[docs]</a>  <span class="k">def</span> <span class="nf">UpdateGroupReversePermission</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cidr_block</span><span class="p">,</span> <span class="n">group_name</span><span class="p">,</span> 
                                   <span class="n">new_permissions</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Updates forward zone group permissions</span>

<span class="sd">    Inputs:</span>
<span class="sd">      cidr_block: string of cidr_block</span>
<span class="sd">      group_name: string of group name</span>
<span class="sd">      new_permissions: list of permissions. (ex [u&#39;a&#39;, u&#39;aaaa&#39;, u&#39;cname&#39;])</span>

<span class="sd">    Raises:</span>
<span class="sd">      AuthorizationError: Group does not have access to supplied cidr block</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">reverse_range_permissions</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ListReverseRangePermissions</span><span class="p">(</span><span class="n">cidr_block</span><span class="p">,</span> 
                                                                 <span class="n">group_name</span><span class="p">)</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">group_name</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">reverse_range_permissions</span> <span class="p">):</span>
      <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">AuthorizationError</span><span class="p">(</span><span class="s">&#39;Trying to update permissions on cidr &#39;</span>
                                      <span class="s">&#39;</span><span class="si">%s</span><span class="s"> not assigned to group </span><span class="si">%s</span><span class="s">.&#39;</span> <span class="o">%</span> <span class="p">(</span>
                                      <span class="n">cidr_block</span><span class="p">,</span> <span class="n">group_name</span><span class="p">))</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="n">current_permissions</span> <span class="o">=</span> <span class="n">reverse_range_permissions</span><span class="p">[</span><span class="n">group_name</span><span class="p">]</span>
      <span class="k">for</span> <span class="n">permission</span> <span class="ow">in</span> <span class="n">current_permissions</span><span class="p">:</span>
        <span class="k">if</span><span class="p">(</span> <span class="n">permission</span><span class="p">[</span><span class="s">&#39;cidr_block&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="n">cidr_block</span> <span class="p">):</span>
          <span class="n">current_permissions</span> <span class="o">=</span> <span class="n">permission</span><span class="p">[</span><span class="s">&#39;group_permission&#39;</span><span class="p">]</span>
          <span class="k">break</span>
      <span class="k">else</span><span class="p">:</span>
        <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">AuthorizationError</span><span class="p">(</span><span class="s">&#39;Trying to update permissions on cidr &#39;</span>
                                        <span class="s">&#39;</span><span class="si">%s</span><span class="s"> not assigned to group </span><span class="si">%s</span><span class="s">.&#39;</span> <span class="o">%</span> <span class="p">(</span>
                                        <span class="n">cidr_block</span><span class="p">,</span> <span class="n">group_name</span><span class="p">))</span>

    <span class="n">add_permissions</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">set</span><span class="p">(</span><span class="n">new_permissions</span><span class="p">)</span><span class="o">.</span><span class="n">difference</span><span class="p">(</span><span class="nb">set</span><span class="p">(</span>
        <span class="n">current_permissions</span><span class="p">)))</span>
    <span class="n">remove_permissions</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">set</span><span class="p">(</span><span class="n">current_permissions</span><span class="p">)</span><span class="o">.</span><span class="n">difference</span><span class="p">(</span><span class="nb">set</span><span class="p">(</span>
        <span class="n">new_permissions</span><span class="p">)))</span>

    <span class="n">reverse_range_permissions_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;reverse_range_permissions&#39;</span><span class="p">)</span>
    <span class="n">group_reverse_permissions_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;group_reverse_permissions&#39;</span><span class="p">)</span>

    <span class="n">reverse_range_permissions_dict</span><span class="p">[</span>
        <span class="s">&#39;reverse_range_permissions_group_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">group_name</span>
    <span class="n">reverse_range_permissions_dict</span><span class="p">[</span>
        <span class="s">&#39;reverse_range_permissions_cidr_block&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">cidr_block</span>

    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>       
        <span class="n">reverse_range_permissions_row</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
            <span class="s">&#39;reverse_range_permissions&#39;</span><span class="p">,</span> <span class="n">reverse_range_permissions_dict</span><span class="p">)</span>

        <span class="nb">id</span> <span class="o">=</span> <span class="n">reverse_range_permissions_row</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s">&#39;reverse_range_permissions_id&#39;</span><span class="p">]</span>
        <span class="n">group_reverse_permissions_dict</span><span class="p">[</span>
            <span class="s">&#39;group_reverse_permissions_reverse_range_permissions_id&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">id</span>

        <span class="k">for</span> <span class="n">permission</span> <span class="ow">in</span> <span class="n">remove_permissions</span><span class="p">:</span>
          <span class="n">group_reverse_permissions_dict</span><span class="p">[</span>
              <span class="s">&#39;group_reverse_permissions_group_permission&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">permission</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">RemoveRow</span><span class="p">(</span><span class="s">&#39;group_reverse_permissions&#39;</span><span class="p">,</span>
                                      <span class="n">group_reverse_permissions_dict</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">permission</span> <span class="ow">in</span> <span class="n">add_permissions</span><span class="p">:</span>
          <span class="n">group_reverse_permissions_dict</span><span class="p">[</span>
              <span class="s">&#39;group_reverse_permissions_group_permission&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">permission</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">MakeRow</span><span class="p">(</span><span class="s">&#39;group_reverse_permissions&#39;</span><span class="p">,</span>
                                    <span class="n">group_reverse_permissions_dict</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
      <span class="k">if</span><span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">parent_server_instance</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">parent_server_instance</span><span class="o">.</span><span class="n">SetCoreCacheDirty</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="Core.RemoveReverseRangePermission"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.RemoveReverseRangePermission">[docs]</a>  <span class="k">def</span> <span class="nf">RemoveReverseRangePermission</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cidr_block</span><span class="p">,</span> <span class="n">group_name</span><span class="p">,</span>
                                   <span class="n">group_permission</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Remove reverse range permissions.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      cidr_block: string of cidr block</span>
<span class="sd">      group_name: string of group name</span>
<span class="sd">      group_permission: list of group permissions, i.e., [&#39;a&#39;, &#39;aaaa&#39;, &#39;cname&#39;]</span>

<span class="sd">    Outputs:</span>
<span class="sd">      int: number of rows affected</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">reverse_range_permissions_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;reverse_range_permissions&#39;</span><span class="p">)</span>
    <span class="n">reverse_range_permissions_dict</span><span class="p">[</span><span class="s">&#39;reverse_range_permissions_group_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
        <span class="n">group_name</span><span class="p">)</span>
    <span class="n">reverse_range_permissions_dict</span><span class="p">[</span><span class="s">&#39;reverse_range_permissions_cidr_block&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
        <span class="n">cidr_block</span><span class="p">)</span>

    <span class="n">row_count</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="n">group_reverse_permissions_rows</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">reverse_range_permissions_rows</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
            <span class="s">&#39;reverse_range_permissions&#39;</span><span class="p">,</span> <span class="n">reverse_range_permissions_dict</span><span class="p">)</span>
        <span class="k">if</span><span class="p">(</span> <span class="nb">len</span><span class="p">(</span><span class="n">reverse_range_permissions_rows</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span> <span class="p">):</span>
          <span class="k">for</span> <span class="n">permission</span> <span class="ow">in</span> <span class="n">group_permission</span><span class="p">:</span>
            <span class="n">group_reverse_permissions_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
                <span class="s">&#39;group_reverse_permissions&#39;</span><span class="p">)</span>
            <span class="n">group_reverse_permissions_dict</span><span class="p">[</span>
                <span class="s">&#39;group_reverse_permissions_group_permission&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">permission</span>
            <span class="n">group_reverse_permissions_rows</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
                <span class="s">&#39;group_reverse_permissions&#39;</span><span class="p">,</span>
                <span class="n">group_reverse_permissions_dict</span><span class="p">))</span>

        <span class="k">for</span> <span class="n">row</span> <span class="ow">in</span> <span class="n">reverse_range_permissions_rows</span><span class="p">:</span>
          <span class="n">reverse_range_permissions_dict</span><span class="p">[</span><span class="s">&#39;reverse_range_permissions_id&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">row</span><span class="p">[</span>
              <span class="s">&#39;reverse_range_permissions_id&#39;</span><span class="p">]</span>
          <span class="n">group_reverse_permissions_list</span> <span class="o">=</span> <span class="p">[]</span>

          <span class="k">if</span><span class="p">(</span> <span class="n">group_permission</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="p">):</span>
            <span class="k">for</span> <span class="n">permission</span> <span class="ow">in</span> <span class="n">group_permission</span><span class="p">:</span>
              <span class="n">group_reverse_permissions_dict</span> <span class="o">=</span> <span class="p">{</span>
                  <span class="s">&#39;group_reverse_permissions_reverse_range_permissions_id&#39;</span><span class="p">:</span> <span class="p">(</span>
                      <span class="n">row</span><span class="p">[</span><span class="s">&#39;reverse_range_permissions_id&#39;</span><span class="p">]),</span>
                  <span class="s">&#39;group_reverse_permissions_group_permission&#39;</span><span class="p">:</span> <span class="n">permission</span><span class="p">}</span>
              <span class="n">group_reverse_permissions_rows</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
                  <span class="s">&#39;group_reverse_permissions&#39;</span><span class="p">,</span>
                  <span class="n">group_reverse_permissions_dict</span><span class="p">)</span>
              <span class="k">for</span> <span class="n">group_reverse_permissions_row</span> <span class="ow">in</span> <span class="p">(</span>
                      <span class="n">group_reverse_permissions_rows</span><span class="p">):</span>
                <span class="n">group_reverse_permissions_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                    <span class="n">group_reverse_permissions_row</span><span class="p">[</span>
                        <span class="s">&#39;group_reverse_permissions_group_permission&#39;</span><span class="p">])</span>
              <span class="k">if</span><span class="p">(</span> <span class="n">group_permission</span> <span class="o">==</span> <span class="n">group_reverse_permissions_list</span> <span class="p">):</span>
                <span class="n">row_count</span> <span class="o">=</span> <span class="n">row_count</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">RemoveRow</span><span class="p">(</span>
                    <span class="s">&#39;reverse_range_permissions&#39;</span><span class="p">,</span> <span class="n">reverse_range_permissions_dict</span><span class="p">)</span>
          <span class="k">else</span><span class="p">:</span>
            <span class="n">row_count</span> <span class="o">=</span> <span class="n">row_count</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">RemoveRow</span><span class="p">(</span>
                <span class="s">&#39;reverse_range_permissions&#39;</span><span class="p">,</span> <span class="n">reverse_range_permissions_dict</span><span class="p">)</span>
          <span class="c">## Associated group_reverse_permissions deleted by CASCADE in DB</span>

      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
      <span class="k">if</span><span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">parent_server_instance</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">parent_server_instance</span><span class="o">.</span><span class="n">SetCoreCacheDirty</span><span class="p">()</span>

    <span class="k">return</span> <span class="n">row_count</span>
</div>
<div class="viewcode-block" id="Core.GetEmptyRecordArgsDict"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.GetEmptyRecordArgsDict">[docs]</a>  <span class="k">def</span> <span class="nf">GetEmptyRecordArgsDict</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">record_type</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Gets record args dict for the record_type.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      record_type: string of record type (example: u&#39;mx&#39;)</span>

<span class="sd">    Outputs:</span>
<span class="sd">      dictionary: which is different for each record type.</span>
<span class="sd">                 (example: {u&#39;priority&#39;: 10,</span>
<span class="sd">                            u&#39;mail_server&#39;: &#39;mail.sub.university.edu.&#39;})</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRecordArgsDict</span><span class="p">(</span><span class="n">record_type</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Core.ListRecords"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.ListRecords">[docs]</a>  <span class="k">def</span> <span class="nf">ListRecords</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">record_type</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">zone_name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                  <span class="n">view_name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">ttl</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">record_args_dict</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Lists records.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      record_type: string of record type (example: u&#39;mx&#39;)</span>
<span class="sd">      target: string of target (example u&#39;machine-01.sub.univeristy.edu.&#39;)</span>
<span class="sd">      zone_name: string of zone name (example u&#39;sub.university.edu&#39;)</span>
<span class="sd">      ttl: int of time to live per record</span>
<span class="sd">      view_name: string of view name (example u&#39;internal&#39;)</span>
<span class="sd">      record_args_dict: dictionary, which is different for each record type.</span>
<span class="sd">                        an example dictionary can be obtained with the</span>
<span class="sd">                        GetEmptyRecordArgsDict function in this class</span>
<span class="sd">                        (example: {u&#39;priority&#39;: 10,</span>
<span class="sd">                                   u&#39;mail_server&#39;: &#39;mail.sub.university.edu.&#39;})</span>
<span class="sd">    </span>
<span class="sd">    Raises:</span>
<span class="sd">      UnexpectedDataError: Must specify record_type with record_args_dict.</span>

<span class="sd">    Outputs:</span>
<span class="sd">      list of record dictionaries</span>
<span class="sd">        Each dictionary can have different args depending on record type.</span>
<span class="sd">        All of them will include record_type, target, zone_name, ttl, and</span>
<span class="sd">        view_name regardless of record type. Below is an example of an mx</span>
<span class="sd">        record search.</span>
<span class="sd">        example: [{&#39;record_type&#39;: &#39;mx&#39;, &#39;target&#39;: &#39;university.edu.&#39;,</span>
<span class="sd">                   &#39;zone_name&#39;: &#39;university.edu&#39;, ttl: 3600,</span>
<span class="sd">                   &#39;view_name&#39;: &#39;external&#39;, &#39;priority&#39;: 10,</span>
<span class="sd">                   &#39;mail_server&#39;: &#39;smtp-01.university.edu.&#39;,</span>
<span class="sd">                   &#39;last_user&#39;: &#39;sharrell},</span>
<span class="sd">                  {&#39;record_type&#39;: &#39;mx&#39;, &#39;target&#39;: &#39;university.edu.&#39;,</span>
<span class="sd">                   &#39;zone_name&#39;: &#39;university.edu&#39;, ttl: 3600,</span>
<span class="sd">                   &#39;view_name&#39;: &#39;external&#39;, &#39;priority&#39;: 20,</span>
<span class="sd">                   &#39;mail_server&#39;: &#39;smtp-02.university.edu.&#39;},</span>
<span class="sd">                   &#39;last_user&#39;: &#39;sharrell}]</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">record_args_dict</span><span class="p">:</span>
      <span class="n">record_args_dict</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="s">&#39;ListRecords&#39;</span><span class="p">)</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">view_name</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="n">view_name</span> <span class="o">!=</span> <span class="s">u&#39;any&#39;</span> <span class="ow">and</span> <span class="ow">not</span>
          <span class="n">view_name</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s">&#39;_dep&#39;</span><span class="p">)</span> <span class="p">):</span>
      <span class="n">view_name</span> <span class="o">=</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">_dep&#39;</span> <span class="o">%</span> <span class="n">view_name</span>
    <span class="n">records_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;records&#39;</span><span class="p">)</span>
    <span class="n">record_args_assignment_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;record_arguments_records_assignments&#39;</span><span class="p">)</span>
    <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_type&#39;</span><span class="p">]</span> <span class="o">=</span>  <span class="n">record_type</span>
    <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_target&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">target</span>
    <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_ttl&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ttl</span>
    <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_zone_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">zone_name</span>
    <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_view_dependency&#39;</span><span class="p">]</span> <span class="o">=</span>  <span class="n">view_name</span>

    <span class="k">if</span><span class="p">(</span> <span class="n">record_args_dict</span> <span class="p">):</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">record_type</span> <span class="ow">is</span> <span class="bp">None</span> <span class="p">):</span>
        <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">UnexpectedDataError</span><span class="p">(</span><span class="s">&#39;Must specify record_type with &#39;</span>
                                         <span class="s">&#39;record_args_dict&#39;</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ValidateRecordArgsDict</span><span class="p">(</span><span class="n">record_type</span><span class="p">,</span> <span class="n">record_args_dict</span><span class="p">,</span>
                                              <span class="n">none_ok</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="n">record_args_dict</span> <span class="o">=</span> <span class="p">{}</span>



    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="n">records</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;records&#39;</span><span class="p">,</span> <span class="n">records_dict</span><span class="p">,</span>
                                         <span class="s">&#39;record_arguments_records_assignments&#39;</span><span class="p">,</span>
                                         <span class="n">record_args_assignment_dict</span><span class="p">)</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>

    <span class="k">return</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetRecordsFromRecordRowsAndArgumentRows</span><span class="p">(</span>
        <span class="n">records</span><span class="p">,</span> <span class="n">record_args_dict</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Core.MakeRecord"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.MakeRecord">[docs]</a>  <span class="k">def</span> <span class="nf">MakeRecord</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">record_type</span><span class="p">,</span> <span class="n">target</span><span class="p">,</span> <span class="n">zone_name</span><span class="p">,</span> <span class="n">record_args_dict</span><span class="p">,</span>
                 <span class="n">view_name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">ttl</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Makes a record.</span>

<span class="sd">    Please check core_helpers for functions to make certain records that</span>
<span class="sd">    need help before using this directly. For instance MakePTRRecord and</span>
<span class="sd">    MakeAAAARecord.</span>

<span class="sd">    Raises:</span>
<span class="sd">      InvalidInputError: &quot;.&quot; not allowed as terminator in non-ptr target.</span>
<span class="sd">      InvalidInputError: An SOA cannot be made in the &quot;any&quot; view.</span>
<span class="sd">      InvalidInputError: CNAME already exists.</span>
<span class="sd">      InvalidInputError: Record already exists.</span>
<span class="sd">      InvalidInputError: Duplicate record found.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      record_type: string of record type (example: u&#39;mx&#39;)</span>
<span class="sd">      target: string of target (example u&#39;machine-01&#39;)</span>
<span class="sd">      zone_name: string of zone name (example u&#39;sub.university.edu&#39;)</span>
<span class="sd">      ttl: int of time to live per record</span>
<span class="sd">      view_name: string of view name (example u&#39;internal&#39;)</span>
<span class="sd">      record_args_dict: dictionary, which is different for each record type.</span>
<span class="sd">                        an example dictionary can be obtained with the</span>
<span class="sd">                        GetEmptyRecordArgsDict function in this class</span>
<span class="sd">                        (example: {u&#39;priority&#39;: 10,</span>
<span class="sd">                                   u&#39;mail_server&#39;: &#39;mail.sub.university.edu.&#39;})</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span><span class="p">(</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">data_validation_instance</span><span class="o">.</span><span class="n">isTarget</span><span class="p">(</span><span class="n">target</span><span class="p">)</span> <span class="p">):</span>
      <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span><span class="s">&#39;Target hostname is invalid. </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">target</span><span class="p">)</span>  

    <span class="k">if</span><span class="p">(</span> <span class="n">record_type</span> <span class="o">!=</span> <span class="s">u&#39;ptr&#39;</span> <span class="p">):</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">target</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s">&#39;.&#39;</span><span class="p">)</span> <span class="p">):</span>
        <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span><span class="s">&#39;&quot;.&quot; not allowed as terminator in &#39;</span>
                                       <span class="s">&#39;non-ptr target.&#39;</span><span class="p">)</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ValidateRecordArgsDict</span><span class="p">(</span><span class="n">record_type</span><span class="p">,</span> <span class="n">record_args_dict</span><span class="p">)</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">view_name</span> <span class="ow">is</span> <span class="bp">None</span> <span class="ow">or</span> <span class="n">view_name</span> <span class="o">==</span> <span class="s">u&#39;any&#39;</span><span class="p">):</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">record_type</span> <span class="o">==</span> <span class="s">u&#39;soa&#39;</span> <span class="p">):</span>
        <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span>
            <span class="s">&#39;An SOA cannot be made in the &quot;any&quot; view.&#39;</span><span class="p">)</span>
      <span class="n">view_name</span> <span class="o">=</span> <span class="s">u&#39;any&#39;</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="n">view_name</span> <span class="o">=</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">_dep&#39;</span> <span class="o">%</span> <span class="n">view_name</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">,</span> <span class="p">{</span><span class="s">&#39;target&#39;</span><span class="p">:</span> <span class="n">target</span><span class="p">,</span>
                                                 <span class="s">&#39;zone_name&#39;</span><span class="p">:</span> <span class="n">zone_name</span><span class="p">,</span>
                                                 <span class="s">&#39;view_name&#39;</span><span class="p">:</span> <span class="n">view_name</span><span class="p">,</span>
                                                 <span class="s">&#39;record_type&#39;</span><span class="p">:</span> <span class="n">record_type</span><span class="p">,</span>
                                        <span class="s">&#39;record_args_dict&#39;</span> <span class="p">:</span> <span class="n">record_args_dict</span><span class="p">})</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">ttl</span> <span class="ow">is</span> <span class="bp">None</span> <span class="p">):</span>
      <span class="n">ttl</span> <span class="o">=</span> <span class="n">constants</span><span class="o">.</span><span class="n">DEFAULT_TTL</span>

    <span class="k">if</span><span class="p">(</span> <span class="n">record_type</span> <span class="ow">in</span> <span class="p">[</span><span class="s">&#39;cname&#39;</span><span class="p">,</span> <span class="s">&#39;a&#39;</span><span class="p">,</span> <span class="s">&#39;aaaa&#39;</span><span class="p">]</span> <span class="p">):</span>
      <span class="n">search_type</span> <span class="o">=</span> <span class="bp">None</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="n">search_type</span> <span class="o">=</span> <span class="n">record_type</span>
    <span class="n">records_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;records_id&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>
                    <span class="s">&#39;record_target&#39;</span><span class="p">:</span> <span class="n">target</span><span class="p">,</span>
                    <span class="s">&#39;record_type&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>
                    <span class="s">&#39;record_ttl&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>
                    <span class="s">&#39;record_zone_name&#39;</span><span class="p">:</span> <span class="n">zone_name</span><span class="p">,</span>
                    <span class="s">&#39;record_view_dependency&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>
                    <span class="s">&#39;record_last_user&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">}</span>
    <span class="n">record_args_assignment_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;record_arguments_records_assignments&#39;</span><span class="p">)</span>

    <span class="n">zone_view_assignments_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;zone_view_assignments&#39;</span><span class="p">)</span>
    <span class="n">zone_view_assignments_dict</span><span class="p">[</span><span class="s">&#39;zone_view_assignments_zone_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">zone_name</span>
    <span class="n">zone_view_assignments_dict</span><span class="p">[</span><span class="s">&#39;zone_view_assignments_view_dependency&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">view_name</span>

    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="n">view_assignments</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
            <span class="s">&#39;view_dependency_assignments&#39;</span><span class="p">,</span>
            <span class="p">{</span><span class="s">&#39;view_dependency_assignments_view_name&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>
             <span class="s">&#39;view_dependency_assignments_view_dependency&#39;</span><span class="p">:</span> <span class="n">view_name</span><span class="p">})</span>
        <span class="n">views</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">view_deps</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">view_assignment</span> <span class="ow">in</span> <span class="n">view_assignments</span><span class="p">:</span>
          <span class="k">if</span><span class="p">(</span> <span class="n">view_assignment</span><span class="p">[</span><span class="s">&#39;view_dependency_assignments_view_name&#39;</span><span class="p">]</span> 
              <span class="ow">not</span> <span class="ow">in</span> <span class="n">views</span> <span class="p">):</span>
            <span class="n">views</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">view_assignment</span><span class="p">[</span><span class="s">&#39;view_dependency_assignments_&#39;</span>
                                         <span class="s">&#39;view_name&#39;</span><span class="p">])</span>
          <span class="n">view_assignments_dependencies</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
              <span class="s">&#39;view_dependency_assignments&#39;</span><span class="p">,</span>
              <span class="p">{</span><span class="s">&#39;view_dependency_assignments_view_name&#39;</span><span class="p">:</span> <span class="n">view_assignment</span><span class="p">[</span><span class="s">&#39;view_&#39;</span>
                  <span class="s">&#39;dependency_assignments_view_name&#39;</span><span class="p">],</span>
              <span class="s">&#39;view_dependency_assignments_view_dependency&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">})</span>
          <span class="k">for</span> <span class="n">view</span> <span class="ow">in</span> <span class="n">view_assignments_dependencies</span><span class="p">:</span>
            <span class="k">if</span><span class="p">(</span> <span class="n">view</span><span class="p">[</span><span class="s">&#39;view_dependency_assignments_view_dependency&#39;</span><span class="p">]</span> 
                <span class="ow">not</span> <span class="ow">in</span> <span class="n">view_deps</span> <span class="p">):</span>
              <span class="n">view_deps</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">view</span><span class="p">[</span><span class="s">&#39;view_dependency_&#39;</span>
                                    <span class="s">&#39;assignments_view_dependency&#39;</span><span class="p">])</span>

        <span class="n">zone_view_assignments</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;zone_view_assignments&#39;</span><span class="p">,</span>
            <span class="n">zone_view_assignments_dict</span><span class="p">)</span>

        <span class="c">#This check isn&#39;t *strictly* needed because user.py Authorize() will </span>
        <span class="c">#catch it. However, we thought it good to keep in for the future.</span>
        <span class="k">if</span><span class="p">(</span> <span class="nb">len</span><span class="p">(</span><span class="n">zone_view_assignments</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span> <span class="p">):</span>
          <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">RecordError</span><span class="p">(</span><span class="s">&#39;Zone </span><span class="si">%s</span><span class="s"> not found in view </span><span class="si">%s</span><span class="s">.&#39;</span> <span class="o">%</span> <span class="p">(</span>
            <span class="n">zone_name</span><span class="p">,</span> <span class="n">view_name</span><span class="p">))</span>
        <span class="k">elif</span><span class="p">(</span> <span class="nb">len</span><span class="p">(</span><span class="n">zone_view_assignments</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span> <span class="p">):</span>
          <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">RecordError</span><span class="p">(</span><span class="s">&#39;Multiple zone-view assignments for &#39;</span>
                                   <span class="s">&#39;zone </span><span class="si">%s</span><span class="s"> and view </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">zone_name</span><span class="p">,</span> <span class="n">view_name</span><span class="p">))</span>
        <span class="k">else</span><span class="p">:</span>
          <span class="n">zone_view_assignment</span> <span class="o">=</span> <span class="n">zone_view_assignments</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

        <span class="n">zone_type</span> <span class="o">=</span> <span class="n">zone_view_assignment</span><span class="p">[</span><span class="s">&#39;zone_view_assignments_zone_type&#39;</span><span class="p">]</span>
        <span class="k">if</span><span class="p">(</span> <span class="n">zone_type</span> <span class="o">!=</span> <span class="s">u&#39;master&#39;</span> <span class="p">):</span>
          <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span><span class="s">&#39;Cannot create records in </span><span class="si">%s</span><span class="s"> zone </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span>
              <span class="n">zone_type</span><span class="p">,</span> <span class="n">zone_name</span><span class="p">))</span>

        <span class="k">if</span><span class="p">(</span> <span class="n">record_type</span> <span class="o">==</span> <span class="s">&#39;cname&#39;</span> <span class="p">):</span>
          <span class="n">all_records</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;records&#39;</span><span class="p">,</span> <span class="n">records_dict</span><span class="p">)</span>
          <span class="k">if</span><span class="p">(</span> <span class="nb">len</span><span class="p">(</span><span class="n">all_records</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="p">):</span>
            <span class="k">for</span> <span class="n">record</span> <span class="ow">in</span> <span class="n">all_records</span><span class="p">:</span>
              <span class="k">if</span><span class="p">(</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_view_dependency&#39;</span><span class="p">]</span> <span class="ow">in</span> <span class="n">view_deps</span> <span class="p">):</span>
                <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span><span class="s">&#39;Record already exists with &#39;</span>
                                               <span class="s">&#39;target </span><span class="si">%s</span><span class="s">.&#39;</span> <span class="o">%</span> <span class="n">target</span><span class="p">)</span>
            <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span><span class="s">&#39;Record already exists with &#39;</span>
                                           <span class="s">&#39;target </span><span class="si">%s</span><span class="s">.&#39;</span> <span class="o">%</span> <span class="n">target</span><span class="p">)</span>
        <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s">u&#39;cname&#39;</span>
        <span class="n">cname_records</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
            <span class="s">&#39;records&#39;</span><span class="p">,</span> <span class="n">records_dict</span><span class="p">)</span>
        <span class="k">if</span><span class="p">(</span> <span class="nb">len</span><span class="p">(</span><span class="n">cname_records</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="p">):</span>
          <span class="k">for</span> <span class="n">record</span> <span class="ow">in</span> <span class="n">cname_records</span><span class="p">:</span>
            <span class="k">if</span><span class="p">(</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_view_dependency&#39;</span><span class="p">]</span> <span class="ow">in</span> <span class="n">view_deps</span> <span class="p">):</span>
              <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span><span class="s">&#39;CNAME already exists with &#39;</span>
                                             <span class="s">&#39;target </span><span class="si">%s</span><span class="s">.&#39;</span> <span class="o">%</span> <span class="n">target</span><span class="p">)</span>

        <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">search_type</span>
        <span class="n">raw_records</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
            <span class="s">&#39;records&#39;</span><span class="p">,</span> <span class="n">records_dict</span><span class="p">,</span> <span class="s">&#39;record_arguments_records_assignments&#39;</span><span class="p">,</span>
            <span class="n">record_args_assignment_dict</span><span class="p">)</span>

        <span class="n">current_records</span> <span class="o">=</span> <span class="p">(</span>
            <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetRecordsFromRecordRowsAndArgumentRows</span><span class="p">(</span>
                <span class="n">raw_records</span><span class="p">,</span> <span class="n">record_args_dict</span><span class="p">))</span>
        <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_ttl&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ttl</span>
        <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_type</span>
        <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_last_user&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">GetUserName</span><span class="p">()</span>
        
        <span class="k">for</span> <span class="n">record</span> <span class="ow">in</span> <span class="n">current_records</span><span class="p">:</span>
          <span class="k">for</span> <span class="n">arg</span> <span class="ow">in</span> <span class="n">record_args_dict</span><span class="p">:</span>
            <span class="k">if</span><span class="p">(</span> <span class="n">arg</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">record</span> <span class="p">):</span>
              <span class="k">break</span>
            <span class="k">if</span><span class="p">(</span> <span class="n">record_args_dict</span><span class="p">[</span><span class="n">arg</span><span class="p">]</span> <span class="o">!=</span> <span class="n">record</span><span class="p">[</span><span class="n">arg</span><span class="p">]</span> <span class="p">):</span>
              <span class="k">break</span>
          <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span><span class="p">(</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;view_name&#39;</span><span class="p">]</span> <span class="ow">in</span> <span class="n">views</span> <span class="ow">or</span> 
                <span class="n">record</span><span class="p">[</span><span class="s">&#39;view_name&#39;</span><span class="p">]</span> <span class="ow">in</span> <span class="n">view_deps</span> <span class="p">):</span>
              <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span><span class="s">&#39;Duplicate record found&#39;</span><span class="p">)</span>

        <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_type</span>
        <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_view_dependency&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">view_name</span>
        <span class="n">record_id</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">MakeRow</span><span class="p">(</span><span class="s">&#39;records&#39;</span><span class="p">,</span> <span class="n">records_dict</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">arg_name</span> <span class="ow">in</span> <span class="n">record_args_dict</span><span class="p">:</span>
          <span class="n">record_argument_assignments_dict</span> <span class="o">=</span> <span class="p">{</span>
             <span class="s">&#39;record_arguments_records_assignments_record_id&#39;</span><span class="p">:</span> <span class="n">record_id</span><span class="p">,</span>
             <span class="s">&#39;record_arguments_records_assignments_type&#39;</span><span class="p">:</span> <span class="n">record_type</span><span class="p">,</span>
             <span class="s">&#39;record_arguments_records_assignments_argument_name&#39;</span><span class="p">:</span> <span class="n">arg_name</span><span class="p">,</span>
             <span class="s">&#39;argument_value&#39;</span><span class="p">:</span> <span class="nb">unicode</span><span class="p">(</span><span class="n">record_args_dict</span><span class="p">[</span><span class="n">arg_name</span><span class="p">])}</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">MakeRow</span><span class="p">(</span><span class="s">&#39;record_arguments_records_assignments&#39;</span><span class="p">,</span>
                                   <span class="n">record_argument_assignments_dict</span><span class="p">)</span>
        <span class="k">if</span><span class="p">(</span> <span class="n">record_type</span> <span class="ow">in</span> <span class="n">constants</span><span class="o">.</span><span class="n">RECORD_TYPES_INDEXED_BY_IP</span> <span class="p">):</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">_AddRecordToIpIndex</span><span class="p">(</span><span class="n">record_type</span><span class="p">,</span> <span class="n">zone_name</span><span class="p">,</span> <span class="n">view_name</span><span class="p">,</span>
                                   <span class="n">record_id</span><span class="p">,</span> <span class="n">target</span><span class="p">,</span> <span class="n">record_args_dict</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_IncrementSoa</span><span class="p">(</span><span class="n">view_name</span><span class="p">,</span> <span class="n">zone_name</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Core.UpdateRecord"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.UpdateRecord">[docs]</a>  <span class="k">def</span> <span class="nf">UpdateRecord</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">search_record_type</span><span class="p">,</span> <span class="n">search_target</span><span class="p">,</span> <span class="n">search_zone_name</span><span class="p">,</span>
                   <span class="n">search_record_args_dict</span><span class="p">,</span> <span class="n">search_view_name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                   <span class="n">search_ttl</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">update_target</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">update_zone_name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                   <span class="n">update_record_args_dict</span><span class="o">=</span><span class="p">{},</span> <span class="n">update_view_name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                   <span class="n">update_ttl</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Update record.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      search_record_type: type of record</span>
<span class="sd">      search_target: target</span>
<span class="sd">      search_zone_name: name of zone</span>
<span class="sd">      search_record_args_dict: dictionary of record arguments</span>
<span class="sd">      search_view_name: name of view</span>
<span class="sd">      search_ttl: time to live</span>
<span class="sd">      update_target: target</span>
<span class="sd">      update_zone_name: name of zone</span>
<span class="sd">      update_record_args_dict: dictionary of record arguments</span>
<span class="sd">      update_view_name: name of view</span>
<span class="sd">      update_ttl: time to live</span>

<span class="sd">    Raises:</span>
<span class="sd">      InvalidInputError: &quot;.&quot; not allowed as terminator in non-ptr target.</span>
<span class="sd">      InvalidInputError: Record already exists.</span>
<span class="sd">      InvalidInputError: CNAME already exists.</span>
<span class="sd">      InvalidInputError: Duplicate record found.</span>
<span class="sd">      InvalidInputError: No records found.</span>
<span class="sd">      InvalidInputError: Multiple records found for used search terms.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">search_record_type</span> <span class="o">!=</span> <span class="s">u&#39;ptr&#39;</span> <span class="p">):</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">update_target</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="n">update_target</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s">&#39;.&#39;</span><span class="p">)</span> <span class="p">):</span>
        <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span><span class="s">&#39;&quot;.&quot; not allowed as terminator in &#39;</span>
                                 <span class="s">&#39;non-ptr target.&#39;</span><span class="p">)</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">search_view_name</span> <span class="ow">is</span> <span class="bp">None</span> <span class="p">):</span>
      <span class="n">search_view_name</span> <span class="o">=</span> <span class="s">u&#39;any&#39;</span>
    <span class="k">if</span><span class="p">(</span> <span class="ow">not</span> <span class="n">search_view_name</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s">&#39;_dep&#39;</span><span class="p">)</span> <span class="ow">and</span> <span class="n">search_view_name</span> <span class="o">!=</span> <span class="s">u&#39;any&#39;</span><span class="p">):</span>
      <span class="n">search_view_name</span> <span class="o">=</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">_dep&#39;</span> <span class="o">%</span> <span class="n">search_view_name</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">update_view_name</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">update_view_name</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s">&#39;_dep&#39;</span><span class="p">)</span>
        <span class="ow">and</span> <span class="n">update_view_name</span> <span class="o">!=</span> <span class="s">u&#39;any&#39;</span> <span class="p">):</span>
      <span class="n">update_view_name</span> <span class="o">=</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">_dep&#39;</span> <span class="o">%</span> <span class="n">update_view_name</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">,</span> <span class="p">{</span><span class="s">&#39;target&#39;</span><span class="p">:</span> <span class="n">search_target</span><span class="p">,</span>
                                                 <span class="s">&#39;zone_name&#39;</span><span class="p">:</span> <span class="n">search_zone_name</span><span class="p">,</span>
                                                 <span class="s">&#39;view_name&#39;</span><span class="p">:</span> <span class="n">search_view_name</span><span class="p">,</span>
                                                 <span class="s">&#39;record_type&#39;</span><span class="p">:</span> <span class="n">search_record_type</span><span class="p">,</span>
                                                 <span class="s">&#39;record_args_dict&#39;</span> <span class="p">:</span> <span class="n">search_record_args_dict</span><span class="p">})</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">,</span> <span class="p">{</span><span class="s">&#39;target&#39;</span><span class="p">:</span> <span class="n">update_target</span><span class="p">,</span>
                                                 <span class="s">&#39;zone_name&#39;</span><span class="p">:</span> <span class="n">update_zone_name</span><span class="p">,</span>
                                                 <span class="s">&#39;view_name&#39;</span><span class="p">:</span> <span class="n">update_view_name</span><span class="p">,</span>
                                                 <span class="s">&#39;record_type&#39;</span><span class="p">:</span> <span class="n">search_record_type</span><span class="p">,</span>
                                                 <span class="s">&#39;record_args_dict&#39;</span><span class="p">:</span> <span class="n">update_record_args_dict</span><span class="p">})</span>

    <span class="n">search_records_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;records&#39;</span><span class="p">)</span>
    <span class="n">search_records_dict</span><span class="p">[</span><span class="s">&#39;record_type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">search_record_type</span>
    <span class="n">search_records_dict</span><span class="p">[</span><span class="s">&#39;record_zone_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">search_zone_name</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">search_view_name</span> <span class="ow">is</span> <span class="bp">None</span> <span class="p">):</span>
      <span class="n">search_view_name</span> <span class="o">=</span> <span class="s">u&#39;any&#39;</span>
    <span class="k">if</span><span class="p">(</span> <span class="ow">not</span> <span class="n">search_view_name</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s">&#39;_dep&#39;</span><span class="p">)</span> <span class="ow">and</span> <span class="n">search_view_name</span> <span class="o">!=</span> <span class="s">u&#39;any&#39;</span><span class="p">):</span>
      <span class="n">search_view_name</span> <span class="o">=</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">_dep&#39;</span> <span class="o">%</span> <span class="n">search_view_name</span>
    <span class="n">search_records_dict</span><span class="p">[</span><span class="s">&#39;record_view_dependency&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">search_view_name</span>
    <span class="n">search_records_dict</span><span class="p">[</span><span class="s">&#39;record_ttl&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">search_ttl</span>
    <span class="n">search_args_list</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ValidateRecordArgsDict</span><span class="p">(</span><span class="n">search_record_type</span><span class="p">,</span>
                                            <span class="n">search_record_args_dict</span><span class="p">,</span>
                                            <span class="n">none_ok</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>

    <span class="k">for</span> <span class="n">search_argument</span> <span class="ow">in</span> <span class="n">search_record_args_dict</span><span class="p">:</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">search_record_args_dict</span><span class="p">[</span><span class="n">search_argument</span><span class="p">]</span> <span class="ow">is</span> <span class="bp">None</span> <span class="p">):</span>
        <span class="k">continue</span>
      <span class="n">search_args_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
          <span class="p">{</span><span class="s">u&#39;record_arguments_records_assignments_argument_name&#39;</span><span class="p">:</span>
              <span class="n">search_argument</span><span class="p">,</span>
           <span class="s">u&#39;record_arguments_records_assignments_type&#39;</span><span class="p">:</span> <span class="n">search_record_type</span><span class="p">,</span>
           <span class="s">u&#39;argument_value&#39;</span><span class="p">:</span> <span class="nb">unicode</span><span class="p">(</span><span class="n">search_record_args_dict</span><span class="p">[</span><span class="n">search_argument</span><span class="p">]),</span>
           <span class="s">u&#39;record_arguments_records_assignments_record_id&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">})</span>

    <span class="n">update_records_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;records&#39;</span><span class="p">)</span>
    <span class="n">update_records_dict</span><span class="p">[</span><span class="s">&#39;record_type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">search_record_type</span>
    <span class="n">update_records_dict</span><span class="p">[</span><span class="s">&#39;record_target&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">update_target</span>
    <span class="n">update_records_dict</span><span class="p">[</span><span class="s">&#39;record_zone_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">update_zone_name</span>
    <span class="n">update_records_dict</span><span class="p">[</span><span class="s">&#39;record_view_dependency&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">update_view_name</span>
    <span class="n">update_records_dict</span><span class="p">[</span><span class="s">&#39;record_ttl&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">update_ttl</span>
    <span class="n">update_args_list</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="k">if</span><span class="p">(</span> <span class="n">update_record_args_dict</span> <span class="p">):</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ValidateRecordArgsDict</span><span class="p">(</span><span class="n">search_record_type</span><span class="p">,</span>
                                              <span class="n">update_record_args_dict</span><span class="p">,</span>
                                              <span class="n">none_ok</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>

    <span class="k">for</span> <span class="n">update_argument</span> <span class="ow">in</span> <span class="n">update_record_args_dict</span><span class="p">:</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">update_record_args_dict</span><span class="p">[</span><span class="n">update_argument</span><span class="p">]</span> <span class="ow">is</span> <span class="bp">None</span> <span class="p">):</span>
        <span class="k">continue</span>
      <span class="n">update_args_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
          <span class="p">{</span><span class="s">u&#39;record_arguments_records_assignments_argument_name&#39;</span><span class="p">:</span>
              <span class="n">update_argument</span><span class="p">,</span>
           <span class="s">u&#39;record_arguments_records_assignments_type&#39;</span><span class="p">:</span> <span class="n">search_record_type</span><span class="p">,</span>
           <span class="s">u&#39;argument_value&#39;</span><span class="p">:</span> <span class="nb">unicode</span><span class="p">(</span><span class="n">update_record_args_dict</span><span class="p">[</span><span class="n">update_argument</span><span class="p">]),</span>
           <span class="s">u&#39;record_arguments_records_assignments_record_id&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">})</span>

    <span class="n">record_args_assignment_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;record_arguments_records_assignments&#39;</span><span class="p">)</span>

    <span class="n">merged_records_dict</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">search_records_dict</span><span class="p">:</span>
      <span class="n">merged_records_dict</span><span class="p">[</span><span class="n">helpers_lib</span><span class="o">.</span><span class="n">UnicodeString</span><span class="p">(</span><span class="n">key</span><span class="p">)]</span> <span class="o">=</span> <span class="p">(</span>
          <span class="n">helpers_lib</span><span class="o">.</span><span class="n">UnicodeString</span><span class="p">(</span><span class="n">search_records_dict</span><span class="p">[</span><span class="n">key</span><span class="p">]))</span>
    <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">update_records_dict</span><span class="p">:</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">key</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">merged_records_dict</span> <span class="ow">or</span>
          <span class="n">update_records_dict</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="p">):</span>
        <span class="n">merged_records_dict</span><span class="p">[</span><span class="n">helpers_lib</span><span class="o">.</span><span class="n">UnicodeString</span><span class="p">(</span><span class="n">key</span><span class="p">)]</span> <span class="o">=</span> <span class="p">(</span>
          <span class="n">helpers_lib</span><span class="o">.</span><span class="n">UnicodeString</span><span class="p">(</span><span class="n">update_records_dict</span><span class="p">[</span><span class="n">key</span><span class="p">]))</span>
    <span class="n">merged_record_args_dict</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">search_record_args_dict</span><span class="p">:</span>
      <span class="n">merged_record_args_dict</span><span class="p">[</span><span class="n">helpers_lib</span><span class="o">.</span><span class="n">UnicodeString</span><span class="p">(</span><span class="n">key</span><span class="p">)]</span> <span class="o">=</span> <span class="p">(</span>
          <span class="n">helpers_lib</span><span class="o">.</span><span class="n">UnicodeString</span><span class="p">(</span><span class="n">search_record_args_dict</span><span class="p">[</span><span class="n">key</span><span class="p">]))</span>
    <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">update_record_args_dict</span><span class="p">:</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">key</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">merged_record_args_dict</span> <span class="ow">or</span>
          <span class="n">update_record_args_dict</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="p">):</span>
        <span class="n">merged_record_args_dict</span><span class="p">[</span><span class="n">helpers_lib</span><span class="o">.</span><span class="n">UnicodeString</span><span class="p">(</span><span class="n">key</span><span class="p">)]</span> <span class="o">=</span> <span class="p">(</span>
          <span class="n">helpers_lib</span><span class="o">.</span><span class="n">UnicodeString</span><span class="p">(</span><span class="n">update_record_args_dict</span><span class="p">[</span><span class="n">key</span><span class="p">]))</span>

    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="n">update_records_dict</span><span class="p">[</span><span class="s">&#39;record_type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">None</span>
        <span class="k">if</span><span class="p">(</span> <span class="n">search_record_type</span> <span class="o">==</span> <span class="s">&#39;cname&#39;</span> <span class="p">):</span>
          <span class="n">all_records</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;records&#39;</span><span class="p">,</span>
                                                 <span class="n">update_records_dict</span><span class="p">)</span>
          <span class="k">if</span><span class="p">(</span> <span class="nb">len</span><span class="p">(</span><span class="n">all_records</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="p">):</span>
            <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span>
                <span class="s">&#39;Record already exists with target </span><span class="si">%s</span><span class="s">.&#39;</span> <span class="o">%</span> <span class="p">(</span>
                                     <span class="n">update_target</span><span class="p">))</span>
        <span class="n">update_records_dict</span><span class="p">[</span><span class="s">&#39;record_type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s">u&#39;cname&#39;</span>
        <span class="n">cname_records</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;records&#39;</span><span class="p">,</span>
                                                 <span class="n">update_records_dict</span><span class="p">)</span>
        <span class="k">if</span><span class="p">(</span> <span class="nb">len</span><span class="p">(</span><span class="n">cname_records</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="p">):</span>
          <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span>
              <span class="s">&#39;CNAME already exists with target </span><span class="si">%s</span><span class="s">.&#39;</span> <span class="o">%</span> <span class="p">(</span>
                                   <span class="n">update_target</span><span class="p">))</span>

        <span class="n">update_records_dict</span><span class="p">[</span><span class="s">&#39;record_type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">search_record_type</span>
        <span class="n">raw_records</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
            <span class="s">&#39;records&#39;</span><span class="p">,</span> <span class="n">merged_records_dict</span><span class="p">,</span>
            <span class="s">&#39;record_arguments_records_assignments&#39;</span><span class="p">,</span>
            <span class="n">record_args_assignment_dict</span><span class="p">)</span>

        <span class="n">current_records</span> <span class="o">=</span> <span class="p">(</span>
            <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetRecordsFromRecordRowsAndArgumentRows</span><span class="p">(</span>
                <span class="n">raw_records</span><span class="p">,</span> <span class="n">merged_record_args_dict</span><span class="p">))</span>
        <span class="n">update_records_dict</span><span class="p">[</span><span class="s">&#39;record_ttl&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">update_ttl</span>

        <span class="k">for</span> <span class="n">record</span> <span class="ow">in</span> <span class="n">current_records</span><span class="p">:</span>
          <span class="k">for</span> <span class="n">arg</span> <span class="ow">in</span> <span class="n">update_record_args_dict</span><span class="p">:</span>
            <span class="k">if</span><span class="p">(</span> <span class="n">record</span><span class="p">[</span><span class="n">arg</span><span class="p">]</span> <span class="ow">is</span> <span class="bp">None</span> <span class="p">):</span>
              <span class="k">continue</span>
            <span class="k">if</span><span class="p">(</span> <span class="n">update_record_args_dict</span><span class="p">[</span><span class="n">arg</span><span class="p">]</span> <span class="o">!=</span> <span class="n">record</span><span class="p">[</span><span class="n">arg</span><span class="p">]</span> <span class="p">):</span>
              <span class="k">break</span>
          <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span><span class="s">&#39;Duplicate record found&#39;</span><span class="p">)</span>

        <span class="k">if</span><span class="p">(</span> <span class="n">update_target</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="n">update_target</span> <span class="o">!=</span> <span class="n">search_target</span> <span class="ow">and</span>
            <span class="p">(</span><span class="n">search_record_type</span> <span class="o">==</span> <span class="s">&#39;a&#39;</span> <span class="ow">or</span> <span class="n">search_record_type</span> <span class="o">==</span> <span class="s">&#39;cname&#39;</span><span class="p">)</span> <span class="p">):</span>
          <span class="n">current_records</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;records&#39;</span><span class="p">,</span>
                                                     <span class="n">update_records_dict</span><span class="p">)</span>
        <span class="n">args_search_list</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">record_ids</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">final_id</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">record_id_dict</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">arg</span> <span class="ow">in</span> <span class="n">search_args_list</span><span class="p">:</span>
          <span class="n">args_search_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
              <span class="s">&#39;record_arguments_records_assignments&#39;</span><span class="p">,</span> <span class="n">arg</span><span class="p">))</span>
        <span class="k">for</span> <span class="n">index</span><span class="p">,</span> <span class="n">search_record_args</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">args_search_list</span><span class="p">):</span>
          <span class="n">record_ids</span><span class="o">.</span><span class="n">append</span><span class="p">([])</span>
          <span class="k">for</span> <span class="n">search_args_dict</span> <span class="ow">in</span> <span class="n">search_record_args</span><span class="p">:</span>
            <span class="n">record_ids</span><span class="p">[</span><span class="n">index</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">search_args_dict</span><span class="p">[</span>
                <span class="s">u&#39;record_arguments_records_assignments_record_id&#39;</span><span class="p">])</span>
        <span class="k">for</span> <span class="n">id_list</span> <span class="ow">in</span> <span class="n">record_ids</span><span class="p">:</span>
          <span class="k">for</span> <span class="n">search_id</span> <span class="ow">in</span> <span class="n">id_list</span><span class="p">:</span>
            <span class="k">if</span><span class="p">(</span> <span class="n">search_id</span> <span class="ow">in</span> <span class="n">record_id_dict</span> <span class="p">):</span>
              <span class="n">record_id_dict</span><span class="p">[</span><span class="n">search_id</span><span class="p">]</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="k">else</span><span class="p">:</span>
              <span class="n">record_id_dict</span><span class="p">[</span><span class="n">search_id</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span>
        <span class="n">existing_record_search_dict</span> <span class="o">=</span> <span class="n">search_records_dict</span>
        <span class="n">existing_record_search_dict</span><span class="p">[</span><span class="s">&#39;record_target&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">search_target</span>
        <span class="n">existing_records</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;records&#39;</span><span class="p">,</span>
                                                    <span class="n">existing_record_search_dict</span><span class="p">)</span>
        <span class="n">existing_ids</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">record</span> <span class="ow">in</span> <span class="n">existing_records</span><span class="p">:</span>
          <span class="n">existing_ids</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">record</span><span class="p">[</span><span class="s">&#39;records_id&#39;</span><span class="p">])</span>
        <span class="k">for</span> <span class="n">record_id</span> <span class="ow">in</span> <span class="n">record_id_dict</span><span class="p">:</span>
          <span class="k">if</span><span class="p">(</span> <span class="n">record_id_dict</span><span class="p">[</span><span class="n">record_id</span><span class="p">]</span> <span class="o">==</span> <span class="nb">len</span><span class="p">(</span><span class="n">search_args_list</span><span class="p">)</span> <span class="p">):</span>
            <span class="n">final_id</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">record_id</span><span class="p">)</span>
        <span class="n">final_id_set</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="n">final_id</span><span class="p">)</span><span class="o">.</span><span class="n">intersection</span><span class="p">(</span><span class="nb">set</span><span class="p">(</span><span class="n">existing_ids</span><span class="p">))</span>
        <span class="k">if</span><span class="p">(</span> <span class="nb">len</span><span class="p">(</span><span class="n">final_id_set</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span> <span class="p">):</span>
          <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span><span class="s">&#39;No records found.&#39;</span><span class="p">)</span>
        <span class="k">elif</span><span class="p">(</span> <span class="nb">len</span><span class="p">(</span><span class="n">final_id_set</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span> <span class="p">):</span>
          <span class="n">search_records_dict</span><span class="p">[</span><span class="s">&#39;records_id&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">final_id_set</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span>
          <span class="n">new_records</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;records&#39;</span><span class="p">,</span>
                                                 <span class="n">search_records_dict</span><span class="p">)</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">UpdateRow</span><span class="p">(</span><span class="s">&#39;records&#39;</span><span class="p">,</span> <span class="n">new_records</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span>
                                                  <span class="n">update_records_dict</span><span class="p">)</span>
          <span class="k">for</span> <span class="n">update_args</span> <span class="ow">in</span> <span class="n">update_args_list</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">search_args</span> <span class="ow">in</span> <span class="n">search_args_list</span><span class="p">:</span>
              <span class="k">if</span><span class="p">(</span> <span class="n">search_args</span><span class="p">[</span>
                  <span class="s">&#39;record_arguments_records_assignments_argument_name&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="p">(</span>
                      <span class="n">update_args</span><span class="p">[</span>
                  <span class="s">&#39;record_arguments_records_assignments_argument_name&#39;</span><span class="p">])</span> <span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">UpdateRow</span><span class="p">(</span>
                    <span class="s">&#39;record_arguments_records_assignments&#39;</span><span class="p">,</span>
                    <span class="n">search_args</span><span class="p">,</span> <span class="n">update_args</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
          <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span>
              <span class="s">&#39;Multiple records found for used search &#39;</span>
              <span class="s">&#39;terms.&#39;</span><span class="p">)</span>
        <span class="k">if</span><span class="p">(</span> <span class="n">update_view_name</span> <span class="ow">is</span> <span class="bp">None</span> <span class="p">):</span>
          <span class="n">update_view_name</span> <span class="o">=</span> <span class="n">search_view_name</span>
        <span class="k">if</span><span class="p">(</span> <span class="n">update_zone_name</span> <span class="ow">is</span> <span class="bp">None</span> <span class="p">):</span>
          <span class="n">update_zone_name</span> <span class="o">=</span> <span class="n">search_zone_name</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_IncrementSoa</span><span class="p">(</span><span class="n">update_view_name</span><span class="p">,</span> <span class="n">update_zone_name</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Core.RemoveRecord"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.RemoveRecord">[docs]</a>  <span class="k">def</span> <span class="nf">RemoveRecord</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">record_type</span><span class="p">,</span> <span class="n">target</span><span class="p">,</span> <span class="n">zone_name</span><span class="p">,</span> <span class="n">record_args_dict</span><span class="p">,</span>
                   <span class="n">view_name</span><span class="p">,</span> <span class="n">ttl</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Remove record.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      record_type: type of record</span>
<span class="sd">      target: target name</span>
<span class="sd">      zone_name: name of zone</span>
<span class="sd">      record_args_dict: dictionary of record arguments</span>
<span class="sd">      view_name: name of view</span>
<span class="sd">      ttl: time to live</span>

<span class="sd">    Raises:</span>
<span class="sd">      InvalidInputError: No records found.</span>
<span class="sd">                         Multiple records found for used search terms.</span>
<span class="sd">      RecordError: Could not remove record for an unknown reason.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>

    <span class="k">if</span><span class="p">(</span> <span class="ow">not</span> <span class="n">view_name</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s">&#39;_dep&#39;</span><span class="p">)</span> <span class="ow">and</span> <span class="n">view_name</span> <span class="o">!=</span> <span class="s">u&#39;any&#39;</span><span class="p">):</span>
      <span class="n">view_name</span> <span class="o">=</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">_dep&#39;</span> <span class="o">%</span> <span class="n">view_name</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">,</span> <span class="p">{</span><span class="s">&#39;target&#39;</span><span class="p">:</span> <span class="n">target</span><span class="p">,</span>
                                                 <span class="s">&#39;zone_name&#39;</span><span class="p">:</span> <span class="n">zone_name</span><span class="p">,</span>
                                                 <span class="s">&#39;view_name&#39;</span><span class="p">:</span> <span class="n">view_name</span><span class="p">,</span>
                                                 <span class="s">&#39;record_type&#39;</span><span class="p">:</span> <span class="n">record_type</span><span class="p">,</span>
                                                 <span class="s">&#39;record_args_dict&#39;</span><span class="p">:</span> <span class="n">record_args_dict</span><span class="p">})</span>

    <span class="n">records_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;records&#39;</span><span class="p">)</span>
    <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_type</span>
    <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_target&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">target</span>
    <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_zone_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">zone_name</span>
    <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_view_dependency&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">view_name</span>
    <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_ttl&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ttl</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ValidateRecordArgsDict</span><span class="p">(</span><span class="n">record_type</span><span class="p">,</span> <span class="n">record_args_dict</span><span class="p">)</span>

    <span class="n">args_list</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">argument</span> <span class="ow">in</span> <span class="n">record_args_dict</span><span class="p">:</span>
      <span class="n">args_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
          <span class="p">{</span><span class="s">u&#39;record_arguments_records_assignments_argument_name&#39;</span><span class="p">:</span> <span class="n">argument</span><span class="p">,</span>
           <span class="s">u&#39;record_arguments_records_assignments_type&#39;</span><span class="p">:</span> <span class="n">record_type</span><span class="p">,</span>
           <span class="s">u&#39;argument_value&#39;</span><span class="p">:</span> <span class="nb">unicode</span><span class="p">(</span><span class="n">record_args_dict</span><span class="p">[</span><span class="n">argument</span><span class="p">]),</span>
           <span class="s">u&#39;record_arguments_records_assignments_record_id&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">})</span>
    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="n">new_records</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;records&#39;</span><span class="p">,</span> <span class="n">records_dict</span><span class="p">)</span>
        <span class="n">args_search_list</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">record_ids</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">final_id</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">record_id_dict</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">arg</span> <span class="ow">in</span> <span class="n">args_list</span><span class="p">:</span>
          <span class="n">args_search_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
              <span class="s">&#39;record_arguments_records_assignments&#39;</span><span class="p">,</span> <span class="n">arg</span><span class="p">))</span>
        <span class="k">for</span> <span class="n">index</span><span class="p">,</span> <span class="n">record_args</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">args_search_list</span><span class="p">):</span>
          <span class="n">record_ids</span><span class="o">.</span><span class="n">append</span><span class="p">([])</span>
          <span class="k">for</span> <span class="n">args_dict</span> <span class="ow">in</span> <span class="n">record_args</span><span class="p">:</span>
            <span class="n">record_ids</span><span class="p">[</span><span class="n">index</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">args_dict</span><span class="p">[</span>
                <span class="s">u&#39;record_arguments_records_assignments_record_id&#39;</span><span class="p">])</span>
        <span class="k">for</span> <span class="n">id_list</span> <span class="ow">in</span> <span class="n">record_ids</span><span class="p">:</span>
          <span class="k">for</span> <span class="n">search_id</span> <span class="ow">in</span> <span class="n">id_list</span><span class="p">:</span>
            <span class="k">if</span><span class="p">(</span> <span class="n">search_id</span> <span class="ow">in</span> <span class="n">record_id_dict</span> <span class="p">):</span>
              <span class="n">record_id_dict</span><span class="p">[</span><span class="n">search_id</span><span class="p">]</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="k">else</span><span class="p">:</span>
              <span class="n">record_id_dict</span><span class="p">[</span><span class="n">search_id</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span>
        <span class="k">for</span> <span class="n">record_id</span> <span class="ow">in</span> <span class="n">record_id_dict</span><span class="p">:</span>
          <span class="k">if</span><span class="p">(</span> <span class="n">record_id_dict</span><span class="p">[</span><span class="n">record_id</span><span class="p">]</span> <span class="o">==</span> <span class="nb">len</span><span class="p">(</span><span class="n">args_list</span><span class="p">)</span> <span class="p">):</span>
            <span class="k">for</span> <span class="n">record</span> <span class="ow">in</span> <span class="n">new_records</span><span class="p">:</span>
              <span class="k">if</span><span class="p">(</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;records_id&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="n">record_id</span> <span class="p">):</span>
                <span class="n">final_id</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">record_id</span><span class="p">)</span>
        <span class="k">if</span><span class="p">(</span> <span class="nb">len</span><span class="p">(</span><span class="n">final_id</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span> <span class="p">):</span>
          <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span><span class="s">&#39;No records found.&#39;</span><span class="p">)</span>
        <span class="k">elif</span><span class="p">(</span> <span class="nb">len</span><span class="p">(</span><span class="n">final_id</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span> <span class="p">):</span>
          <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;records_id&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">final_id</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
          <span class="k">for</span> <span class="n">record</span> <span class="ow">in</span> <span class="n">new_records</span><span class="p">:</span>
            <span class="k">if</span><span class="p">(</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;records_id&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="n">final_id</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="p">):</span>
              <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">RemoveRow</span><span class="p">(</span><span class="s">&#39;records&#39;</span><span class="p">,</span> <span class="n">record</span><span class="p">)</span>
              <span class="k">break</span>
          <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">RecordError</span><span class="p">(</span><span class="s">&#39;Could not remove record with ID &quot;</span><span class="si">%s</span><span class="s">&quot; &#39;</span>
                                   <span class="s">&#39;for an unknown reason.&#39;</span> <span class="o">%</span> <span class="n">final_id</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
        <span class="k">else</span><span class="p">:</span>
          <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span>
              <span class="s">&#39;Multiple records found for used search &#39;</span>
              <span class="s">&#39;terms.&#39;</span><span class="p">)</span>
        <span class="n">missing_ok</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="k">if</span><span class="p">(</span> <span class="n">record_type</span> <span class="o">==</span> <span class="s">u&#39;soa&#39;</span> <span class="p">):</span>
          <span class="n">missing_ok</span> <span class="o">=</span> <span class="bp">True</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_IncrementSoa</span><span class="p">(</span><span class="n">view_name</span><span class="p">,</span> <span class="n">zone_name</span><span class="p">,</span> <span class="n">missing_ok</span><span class="o">=</span><span class="n">missing_ok</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Core.ListRecordArgumentDefinitions"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.ListRecordArgumentDefinitions">[docs]</a>  <span class="k">def</span> <span class="nf">ListRecordArgumentDefinitions</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">record_type</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;List record argument definitions. This is mainly for the exporter to</span>
<span class="sd">    programtically construct records for exporting.</span>

<span class="sd">    This function is duplicated in</span>
<span class="sd">    roster-config-manager/roster_config_manager/tree_exporter.py</span>

<span class="sd">    Inputs:</span>
<span class="sd">      record_type: string of record type</span>

<span class="sd">    Outputs:</span>
<span class="sd">      dictionary keyed by record type with values of lists</span>
<span class="sd">        of lists of record arguments sorted by argument order.</span>
<span class="sd">        example: {&#39;mx&#39;: [{&#39;argument_name&#39;: u&#39;priority&#39;,</span>
<span class="sd">                          &#39;record_arguments_type&#39;: u&#39;mx&#39;,</span>
<span class="sd">                          &#39;argument_data_type&#39;: u&#39;UnsignedInt&#39;,</span>
<span class="sd">                          &#39;argument_order&#39;: 0},</span>
<span class="sd">                         {&#39;argument_name&#39;: u&#39;mail_server&#39;,</span>
<span class="sd">                         &#39;record_arguments_type&#39;: u&#39;mx&#39;,</span>
<span class="sd">                         &#39;argument_data_type&#39;: u&#39;Hostname&#39;,</span>
<span class="sd">                         &#39;argument_order&#39;: 1}]}</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="s">&#39;ListRecordArgumentDefinitions&#39;</span><span class="p">)</span>

    <span class="n">search_record_arguments_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;record_arguments&#39;</span><span class="p">)</span>
    <span class="n">search_record_arguments_dict</span><span class="p">[</span><span class="s">&#39;record_arguments_type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_type</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="n">record_arguments</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;record_arguments&#39;</span><span class="p">,</span>
                                                  <span class="n">search_record_arguments_dict</span><span class="p">)</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>

    <span class="n">sorted_record_arguments</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="k">for</span> <span class="n">record_argument</span> <span class="ow">in</span> <span class="n">record_arguments</span><span class="p">:</span>
      <span class="n">current_record_type</span> <span class="o">=</span> <span class="n">record_argument</span><span class="p">[</span><span class="s">&#39;record_arguments_type&#39;</span><span class="p">]</span>
      <span class="k">del</span> <span class="n">record_argument</span><span class="p">[</span><span class="s">&#39;record_arguments_type&#39;</span><span class="p">]</span>
      <span class="k">del</span> <span class="n">record_argument</span><span class="p">[</span><span class="s">&#39;argument_data_type&#39;</span><span class="p">]</span>
      <span class="k">if</span><span class="p">(</span> <span class="ow">not</span> <span class="n">current_record_type</span> <span class="ow">in</span> <span class="n">sorted_record_arguments</span> <span class="p">):</span>
        <span class="n">sorted_record_arguments</span><span class="p">[</span><span class="n">current_record_type</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
      <span class="n">sorted_record_arguments</span><span class="p">[</span><span class="n">current_record_type</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">record_argument</span><span class="p">)</span>

    <span class="k">for</span> <span class="n">record_argument</span> <span class="ow">in</span> <span class="n">sorted_record_arguments</span><span class="p">:</span>
      <span class="n">sorted_record_arguments</span><span class="p">[</span><span class="n">record_argument</span><span class="p">]</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span>
          <span class="n">sorted_record_arguments</span><span class="p">[</span><span class="n">record_argument</span><span class="p">],</span>
          <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">k</span><span class="p">:</span> <span class="n">k</span><span class="p">[</span><span class="s">&#39;argument_order&#39;</span><span class="p">])</span>

    <span class="k">return</span> <span class="n">sorted_record_arguments</span>
</div>
<div class="viewcode-block" id="Core.ListZoneTypes"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.ListZoneTypes">[docs]</a>  <span class="k">def</span> <span class="nf">ListZoneTypes</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Lists zone types.</span>

<span class="sd">       Outputs:</span>
<span class="sd">         list: list of zone types, example: [&#39;master&#39;, &#39;slave&#39;, &#39;forward&#39;]</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="s">&#39;ListZoneTypes&#39;</span><span class="p">)</span>
    <span class="n">zone_types_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;zone_types&#39;</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="n">zone_types</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;zone_types&#39;</span><span class="p">,</span> <span class="n">zone_types_dict</span><span class="p">)</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">type_list</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">zone_type</span> <span class="ow">in</span> <span class="n">zone_types</span><span class="p">:</span>
      <span class="n">type_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">zone_type</span><span class="p">[</span><span class="s">&#39;zone_type&#39;</span><span class="p">])</span>
    <span class="k">return</span> <span class="n">type_list</span>
</div>
<div class="viewcode-block" id="Core.BootstrapZone"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.BootstrapZone">[docs]</a>  <span class="k">def</span> <span class="nf">BootstrapZone</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">zone_name</span><span class="p">,</span> <span class="n">zone_type</span><span class="p">,</span> <span class="n">zone_origin</span><span class="p">,</span> <span class="n">view_name</span><span class="p">,</span> 
      <span class="n">zone_bootstrap_dict</span><span class="p">,</span> <span class="n">zone_options</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">make_any</span><span class="o">=</span><span class="bp">True</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Generates SOA and NS records for a zone.</span>

<span class="sd">       Inputs:</span>
<span class="sd">         zone_bootstrap_dict: dictionary containing between 0 and 2 keys </span>
<span class="sd">                              &#39;admin_email&#39; and &#39;name_server&#39; if either </span>
<span class="sd">                              of those keys are omitted, then their corresponding</span>
<span class="sd">                              values are &#39;generated&#39; by this method.</span>
<span class="sd">        zone_name: string of zone name</span>
<span class="sd">        zone_type: string of zone type</span>
<span class="sd">        zone_origin: string of zone origin. ex dept.univiersity.edu.</span>
<span class="sd">        zone_options: string of zone_options(defaults to empty string)</span>
<span class="sd">                      valid zone options can be found here:</span>
<span class="sd">                        http://www.bind9.net/manual/bind/9.3.2/Bv9ARM.ch06.html#zone_statement_grammar</span>
<span class="sd">        view_name: string of view name(defaults to &#39;any&#39;)</span>
<span class="sd">                   see docstring of MakeViewAssignments as to why &#39;any&#39; is default</span>
<span class="sd">        make_any: regardless of view name, make any as well(default to True)</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">view_name</span> <span class="o">==</span> <span class="s">u&#39;any&#39;</span> <span class="p">):</span>
      <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span><span class="s">&#39;Cannot bootstrap a zone in the &quot;any&quot; view.&#39;</span><span class="p">)</span>

    <span class="k">if</span><span class="p">(</span> <span class="s">&#39;admin_email&#39;</span> <span class="ow">in</span> <span class="n">zone_bootstrap_dict</span> <span class="ow">and</span> 
        <span class="n">zone_bootstrap_dict</span><span class="p">[</span><span class="s">&#39;admin_email&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="p">):</span>
      <span class="n">admin_email</span> <span class="o">=</span> <span class="n">zone_bootstrap_dict</span><span class="p">[</span><span class="s">&#39;admin_email&#39;</span><span class="p">]</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="n">admin_email</span> <span class="o">=</span> <span class="s">u&#39;admin.</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">zone_origin</span>
    <span class="k">if</span><span class="p">(</span> <span class="s">&#39;name_server&#39;</span> <span class="ow">in</span> <span class="n">zone_bootstrap_dict</span> <span class="ow">and</span>
        <span class="n">zone_bootstrap_dict</span><span class="p">[</span><span class="s">&#39;name_server&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="p">):</span>
      <span class="n">name_server</span> <span class="o">=</span> <span class="n">zone_bootstrap_dict</span><span class="p">[</span><span class="s">&#39;name_server&#39;</span><span class="p">]</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="n">name_server</span> <span class="o">=</span> <span class="s">u&#39;ns.</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">zone_origin</span>

    <span class="n">ns_record_args_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">GetEmptyRecordArgsDict</span><span class="p">(</span><span class="s">u&#39;ns&#39;</span><span class="p">)</span>
    <span class="n">soa_record_args_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">GetEmptyRecordArgsDict</span><span class="p">(</span><span class="s">u&#39;soa&#39;</span><span class="p">)</span>

    <span class="n">ns_record_args_dict</span><span class="p">[</span><span class="s">&#39;name_server&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">name_server</span>
    <span class="n">soa_record_args_dict</span><span class="p">[</span><span class="s">&#39;name_server&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">name_server</span>
    <span class="n">soa_record_args_dict</span><span class="p">[</span><span class="s">&#39;admin_email&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">admin_email</span>

    <span class="n">soa_record_args_dict</span><span class="p">[</span><span class="s">&#39;refresh_seconds&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">config_instance</span><span class="o">.</span><span class="n">config_file</span><span class="p">[</span>
          <span class="s">&#39;zone_defaults&#39;</span><span class="p">][</span><span class="s">&#39;refresh_seconds&#39;</span><span class="p">])</span>
    <span class="n">soa_record_args_dict</span><span class="p">[</span><span class="s">&#39;expiry_seconds&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">config_instance</span><span class="o">.</span><span class="n">config_file</span><span class="p">[</span>
          <span class="s">&#39;zone_defaults&#39;</span><span class="p">][</span><span class="s">&#39;expiry_seconds&#39;</span><span class="p">])</span>
    <span class="n">soa_record_args_dict</span><span class="p">[</span><span class="s">&#39;minimum_seconds&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">config_instance</span><span class="o">.</span><span class="n">config_file</span><span class="p">[</span>
          <span class="s">&#39;zone_defaults&#39;</span><span class="p">][</span><span class="s">&#39;minimum_seconds&#39;</span><span class="p">])</span>
    <span class="n">soa_record_args_dict</span><span class="p">[</span><span class="s">&#39;retry_seconds&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">config_instance</span><span class="o">.</span><span class="n">config_file</span><span class="p">[</span>
          <span class="s">&#39;zone_defaults&#39;</span><span class="p">][</span><span class="s">&#39;retry_seconds&#39;</span><span class="p">])</span>
    <span class="n">soa_record_args_dict</span><span class="p">[</span><span class="s">&#39;serial_number&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span> 
    <span class="n">ns_ttl</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">config_instance</span><span class="o">.</span><span class="n">config_file</span><span class="p">[</span><span class="s">&#39;zone_defaults&#39;</span><span class="p">][</span>
        <span class="s">&#39;ns_ttl&#39;</span><span class="p">])</span>
    <span class="n">soa_ttl</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">config_instance</span><span class="o">.</span><span class="n">config_file</span><span class="p">[</span><span class="s">&#39;zone_defaults&#39;</span><span class="p">][</span>
        <span class="s">&#39;soa_ttl&#39;</span><span class="p">])</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">MakeZone</span><span class="p">(</span><span class="n">zone_name</span><span class="p">,</span> <span class="n">zone_type</span><span class="p">,</span> <span class="n">zone_origin</span><span class="p">,</span>
      <span class="n">view_name</span><span class="o">=</span><span class="n">view_name</span><span class="p">,</span> <span class="n">zone_options</span><span class="o">=</span><span class="n">zone_options</span><span class="p">,</span> <span class="n">make_any</span><span class="o">=</span><span class="n">make_any</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">MakeRecord</span><span class="p">(</span><span class="s">u&#39;soa&#39;</span><span class="p">,</span> <span class="s">u&#39;@&#39;</span><span class="p">,</span> <span class="n">zone_name</span><span class="p">,</span> <span class="n">soa_record_args_dict</span><span class="p">,</span>
        <span class="n">view_name</span><span class="o">=</span><span class="n">view_name</span><span class="p">,</span> <span class="n">ttl</span><span class="o">=</span><span class="n">soa_ttl</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">MakeRecord</span><span class="p">(</span><span class="s">u&#39;ns&#39;</span><span class="p">,</span> <span class="s">u&#39;@&#39;</span><span class="p">,</span> <span class="n">zone_name</span><span class="p">,</span> <span class="n">ns_record_args_dict</span><span class="p">,</span> 
        <span class="n">view_name</span><span class="o">=</span><span class="n">view_name</span><span class="p">,</span> <span class="n">ttl</span><span class="o">=</span><span class="n">ns_ttl</span><span class="p">)</span>

    <span class="n">soa_record_args_dict</span><span class="p">[</span><span class="s">&#39;ttl&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">soa_ttl</span>
    <span class="n">ns_record_args_dict</span><span class="p">[</span><span class="s">&#39;ttl&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ns_ttl</span>

    <span class="k">return</span> <span class="n">soa_record_args_dict</span><span class="p">,</span> <span class="n">ns_record_args_dict</span>
</div>
<div class="viewcode-block" id="Core.MakeZoneType"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.MakeZoneType">[docs]</a>  <span class="k">def</span> <span class="nf">MakeZoneType</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">zone_type</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Makes a new zone type.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      zone_type: string of zone type</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">zone_types_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;zone_type&#39;</span><span class="p">:</span> <span class="n">zone_type</span><span class="p">}</span>
    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">MakeRow</span><span class="p">(</span><span class="s">&#39;zone_types&#39;</span><span class="p">,</span> <span class="n">zone_types_dict</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Core.RemoveZoneType"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.RemoveZoneType">[docs]</a>  <span class="k">def</span> <span class="nf">RemoveZoneType</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">zone_type</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Removes a zone type.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      zone_type: string of zone type</span>

<span class="sd">    Outputs:</span>
<span class="sd">      int: number of rows affected</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">search_zone_type_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;zone_types&#39;</span><span class="p">)</span>
    <span class="n">search_zone_type_dict</span><span class="p">[</span><span class="s">&#39;zone_type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">zone_type</span>
    <span class="n">row_count</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="n">found_zone_type</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;zone_types&#39;</span><span class="p">,</span>
                                                   <span class="n">search_zone_type_dict</span><span class="p">,</span>
                                                   <span class="n">lock_rows</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">if</span><span class="p">(</span> <span class="n">found_zone_type</span> <span class="p">):</span>
          <span class="n">row_count</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">RemoveRow</span><span class="p">(</span><span class="s">&#39;zone_types&#39;</span><span class="p">,</span>
                                                  <span class="n">found_zone_type</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">row_count</span>
</div>
<div class="viewcode-block" id="Core.ListNamedConfGlobalOptions"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.ListNamedConfGlobalOptions">[docs]</a>  <span class="k">def</span> <span class="nf">ListNamedConfGlobalOptions</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">option_id</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">dns_server_set</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                                 <span class="n">timestamp</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Lists named conf global options</span>

<span class="sd">    Inputs:</span>
<span class="sd">      option_id: integer of named conf global option id</span>
<span class="sd">      dns_server_set: string of the dns server set name</span>
<span class="sd">      timestamp: datetime object of timestamp to search</span>

<span class="sd">    Outputs:</span>
<span class="sd">      named_conf_list: list of named conf global options</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="s">&#39;ListNamedConfGlobalOptions&#39;</span><span class="p">)</span>
    <span class="n">named_conf_global_options_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;named_conf_global_options&#39;</span><span class="p">)</span>
    <span class="n">named_conf_global_options_dict</span><span class="p">[</span><span class="s">&#39;named_conf_global_options_id&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">option_id</span>
    <span class="n">named_conf_global_options_dict</span><span class="p">[</span>
        <span class="s">&#39;named_conf_global_options_dns_server_set_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">dns_server_set</span>
    <span class="n">named_conf_global_options_dict</span><span class="p">[</span><span class="s">&#39;options_created&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">timestamp</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="n">named_conf_options</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
          <span class="s">&#39;named_conf_global_options&#39;</span><span class="p">,</span> <span class="n">named_conf_global_options_dict</span><span class="p">)</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>

    <span class="n">named_conf_list</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">named_conf_option</span> <span class="ow">in</span> <span class="n">named_conf_options</span><span class="p">:</span>
      <span class="n">global_options</span> <span class="o">=</span> <span class="n">iscpy</span><span class="o">.</span><span class="n">Deserialize</span><span class="p">(</span><span class="n">named_conf_option</span><span class="p">[</span><span class="s">&#39;global_options&#39;</span><span class="p">])</span>
      <span class="n">named_conf_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
          <span class="p">{</span><span class="s">&#39;id&#39;</span><span class="p">:</span> <span class="n">named_conf_option</span><span class="p">[</span><span class="s">&#39;named_conf_global_options_id&#39;</span><span class="p">],</span>
           <span class="s">&#39;dns_server_set_name&#39;</span><span class="p">:</span> <span class="n">named_conf_option</span><span class="p">[</span>
               <span class="s">&#39;named_conf_global_options_dns_server_set_name&#39;</span><span class="p">],</span>
           <span class="s">&#39;timestamp&#39;</span><span class="p">:</span> <span class="n">named_conf_option</span><span class="p">[</span><span class="s">&#39;options_created&#39;</span><span class="p">],</span>
           <span class="s">&#39;options&#39;</span><span class="p">:</span> <span class="n">global_options</span><span class="p">})</span>

    <span class="k">return</span> <span class="n">named_conf_list</span>
</div>
<div class="viewcode-block" id="Core.MakeNamedConfGlobalOption"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.MakeNamedConfGlobalOption">[docs]</a>  <span class="k">def</span> <span class="nf">MakeNamedConfGlobalOption</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dns_server_set</span><span class="p">,</span> <span class="n">options</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Makes named conf global option</span>

<span class="sd">    Inputs:</span>
<span class="sd">      dns_server_set: string of name of dns server set</span>
<span class="sd">      options: string of named conf file</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">named_conf_global_options_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;named_conf_global_options&#39;</span><span class="p">)</span>
    <span class="n">named_conf_global_options_dict</span><span class="p">[</span>
        <span class="s">&#39;named_conf_global_options_dns_server_set_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">dns_server_set</span>
    <span class="n">named_conf_global_options_dict</span><span class="p">[</span><span class="s">&#39;global_options&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s">u&#39;</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">iscpy</span><span class="o">.</span><span class="n">Serialize</span><span class="p">(</span><span class="n">options</span><span class="p">)</span>
    <span class="n">timestamp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">unittest_timestamp</span>
    <span class="k">if</span><span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">unittest_timestamp</span> <span class="ow">is</span> <span class="bp">None</span> <span class="p">):</span>
      <span class="n">timestamp</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">()</span>
    <span class="n">named_conf_global_options_dict</span><span class="p">[</span><span class="s">&#39;options_created&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">timestamp</span>

    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">MakeRow</span><span class="p">(</span><span class="s">&#39;named_conf_global_options&#39;</span><span class="p">,</span>
                                 <span class="n">named_conf_global_options_dict</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Core.MakeReservedWord"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.MakeReservedWord">[docs]</a>  <span class="k">def</span> <span class="nf">MakeReservedWord</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">reserved_word</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Create a reserved word.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      reserved_word: string of reserved word</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">reserved_word_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;reserved_word&#39;</span><span class="p">:</span> <span class="n">reserved_word</span><span class="p">}</span>
    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">MakeRow</span><span class="p">(</span><span class="s">&#39;reserved_words&#39;</span><span class="p">,</span> <span class="n">reserved_word_dict</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Core.ListReservedWords"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.ListReservedWords">[docs]</a>  <span class="k">def</span> <span class="nf">ListReservedWords</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Lists reserved words.</span>

<span class="sd">    Output:</span>
<span class="sd">      list: list of reserved words</span>
<span class="sd">            ex: [&#39;reservedword1&#39;, &#39;reservedword2&#39;]</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="s">&#39;ListReservedWords&#39;</span><span class="p">)</span>
    <span class="n">reserved_word_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;reserved_words&#39;</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="n">reserved_words</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;reserved_words&#39;</span><span class="p">,</span>
          <span class="n">reserved_word_dict</span><span class="p">)</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>

    <span class="n">reserved_word_list</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">reserved_word</span> <span class="ow">in</span> <span class="n">reserved_words</span><span class="p">:</span>
      <span class="n">reserved_word_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">reserved_word</span><span class="p">[</span><span class="s">&#39;reserved_word&#39;</span><span class="p">])</span>

    <span class="k">return</span> <span class="n">reserved_word_list</span>
</div>
<div class="viewcode-block" id="Core.RemoveReservedWord"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.RemoveReservedWord">[docs]</a>  <span class="k">def</span> <span class="nf">RemoveReservedWord</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">reserved_word</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Removes a reserved word.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      reserved_word: string of reserved word</span>

<span class="sd">    Outputs:</span>
<span class="sd">      int: number of rows modified</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">search_reserved_word_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;reserved_words&#39;</span><span class="p">)</span>
    <span class="n">search_reserved_word_dict</span><span class="p">[</span><span class="s">&#39;reserved_word&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">reserved_word</span>
    <span class="n">row_count</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="n">found_reserved_word</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
            <span class="s">&#39;reserved_words&#39;</span><span class="p">,</span> <span class="n">search_reserved_word_dict</span><span class="p">,</span> <span class="n">lock_rows</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">if</span><span class="p">(</span> <span class="n">found_reserved_word</span> <span class="p">):</span>
          <span class="n">row_count</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">RemoveRow</span><span class="p">(</span><span class="s">&#39;reserved_words&#39;</span><span class="p">,</span>
              <span class="n">found_reserved_word</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">row_count</span>
</div>
  <span class="k">def</span> <span class="nf">_IncrementSoa</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">view_name</span><span class="p">,</span> <span class="n">zone_name</span><span class="p">,</span> <span class="n">missing_ok</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Increments soa serial number.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      view_name: string of view name</span>
<span class="sd">      zone_name: string of view namea</span>
<span class="sd">      missing_ok: boolean of whether or not missing SOA records are allowed</span>

<span class="sd">    Raises:</span>
<span class="sd">      InvalidInputError: Multiple SOA records found..</span>
<span class="sd">      RecordError: No SOA record found for zone.</span>

<span class="sd">    Outputs:</span>
<span class="sd">      int: number of rows modified</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">soa_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;records&#39;</span><span class="p">)</span>
    <span class="n">soa_arguments_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;record_arguments_records_assignments&#39;</span><span class="p">)</span>
    <span class="n">zone_view_assignments_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;zone_view_assignments&#39;</span><span class="p">)</span>
    <span class="n">zone_view_assignments_dict</span><span class="p">[</span><span class="s">&#39;zone_view_assignments_zone_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">zone_name</span>
    <span class="n">row_count</span> <span class="o">=</span> <span class="mi">0</span>

    <span class="n">soa_dict</span><span class="p">[</span><span class="s">&#39;record_type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s">u&#39;soa&#39;</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">view_name</span> <span class="ow">is</span> <span class="bp">None</span> <span class="p">):</span>
      <span class="n">view_name</span> <span class="o">=</span> <span class="s">u&#39;any&#39;</span>

    <span class="n">zone_view_assignment_rows</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
        <span class="s">&#39;zone_view_assignments&#39;</span><span class="p">,</span> <span class="n">zone_view_assignments_dict</span><span class="p">)</span>

    <span class="n">zone_view_assignments</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="k">for</span> <span class="n">zone_view_assignment</span> <span class="ow">in</span> <span class="n">zone_view_assignment_rows</span><span class="p">:</span>
      <span class="n">zv_zone_name</span> <span class="o">=</span> <span class="n">zone_view_assignment</span><span class="p">[</span><span class="s">&#39;zone_view_assignments_zone_name&#39;</span><span class="p">]</span>
      <span class="n">zv_view_name</span> <span class="o">=</span> <span class="n">zone_view_assignment</span><span class="p">[</span>
          <span class="s">&#39;zone_view_assignments_view_dependency&#39;</span><span class="p">]</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">zv_zone_name</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">zone_view_assignments</span> <span class="p">):</span>
        <span class="n">zone_view_assignments</span><span class="p">[</span><span class="n">zv_zone_name</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
      <span class="n">zone_view_assignments</span><span class="p">[</span><span class="n">zv_zone_name</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">zv_view_name</span><span class="p">)</span>

    <span class="n">view_deps</span> <span class="o">=</span> <span class="p">[</span><span class="n">view_name</span><span class="p">]</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">view_name</span> <span class="o">!=</span> <span class="s">u&#39;any&#39;</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">view_name</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s">&#39;_dep&#39;</span><span class="p">)</span> <span class="p">):</span>
      <span class="n">view_deps</span> <span class="o">=</span> <span class="p">[</span><span class="s">u&#39;</span><span class="si">%s</span><span class="s">_dep&#39;</span> <span class="o">%</span> <span class="n">view_name</span><span class="p">]</span>
    <span class="k">elif</span><span class="p">(</span> <span class="n">view_name</span> <span class="o">==</span> <span class="s">u&#39;any&#39;</span> <span class="p">):</span>
      <span class="n">view_deps</span> <span class="o">=</span> <span class="n">zone_view_assignments</span><span class="p">[</span><span class="n">zone_name</span><span class="p">]</span>

    <span class="k">for</span> <span class="n">view_name</span> <span class="ow">in</span> <span class="n">view_deps</span><span class="p">:</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">view_name</span> <span class="o">==</span> <span class="s">u&#39;any&#39;</span> <span class="p">):</span>
        <span class="k">continue</span>
      <span class="n">soa_dict</span><span class="p">[</span><span class="s">&#39;record_view_dependency&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">view_name</span>
      <span class="n">soa_dict</span><span class="p">[</span><span class="s">&#39;record_zone_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">zone_name</span>

      <span class="n">soa_records_list</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;records&#39;</span><span class="p">,</span> <span class="n">soa_dict</span><span class="p">)</span>

      <span class="k">if</span><span class="p">(</span> <span class="nb">len</span><span class="p">(</span><span class="n">soa_records_list</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span> <span class="p">):</span>
        <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span><span class="s">&#39;Multiple SOA records found: </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> 
                                       <span class="nb">str</span><span class="p">(</span><span class="n">soa_records_list</span><span class="p">))</span>

      <span class="k">if</span><span class="p">(</span> <span class="nb">len</span><span class="p">(</span><span class="n">soa_records_list</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span> <span class="p">):</span>
        <span class="k">if</span><span class="p">(</span> <span class="ow">not</span> <span class="n">missing_ok</span> <span class="p">):</span>
          <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">RecordError</span><span class="p">(</span>
              <span class="s">&#39;No SOA record found for zone &quot;</span><span class="si">%s</span><span class="s">&quot; view &quot;</span><span class="si">%s</span><span class="s">&quot;.&#39;</span> <span class="o">%</span> <span class="p">(</span>
              <span class="n">zone_name</span><span class="p">,</span> <span class="n">view_name</span><span class="p">))</span>
      <span class="k">else</span><span class="p">:</span>
        <span class="n">soa_records_list</span> <span class="o">=</span> <span class="n">soa_records_list</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="n">soa_arguments_dict</span><span class="p">[</span>
            <span class="s">&#39;record_arguments_records_assignments_record_id&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
                <span class="n">soa_records_list</span><span class="p">[</span><span class="s">&#39;records_id&#39;</span><span class="p">])</span>
        <span class="n">soa_record_arguments</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
            <span class="s">&#39;record_arguments_records_assignments&#39;</span><span class="p">,</span> <span class="n">soa_arguments_dict</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">argument</span> <span class="ow">in</span> <span class="n">soa_record_arguments</span><span class="p">:</span>
          <span class="k">if</span><span class="p">(</span> <span class="n">argument</span><span class="p">[</span>
              <span class="s">&#39;record_arguments_records_assignments_argument_name&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="p">(</span>
                  <span class="s">u&#39;serial_number&#39;</span><span class="p">)</span> <span class="p">):</span>
            <span class="n">serial_number</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">argument</span><span class="p">[</span><span class="s">&#39;argument_value&#39;</span><span class="p">])</span>
            <span class="n">search_soa_dict</span> <span class="o">=</span> <span class="n">argument</span>

        <span class="k">if</span><span class="p">(</span> <span class="n">serial_number</span> <span class="o">&gt;=</span> <span class="n">constants</span><span class="o">.</span><span class="n">MAX_SOA_SERIAL</span> <span class="p">):</span>
          <span class="n">soa_arguments_dict</span><span class="p">[</span><span class="s">u&#39;argument_value&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s">u&#39;1&#39;</span>
        <span class="k">else</span><span class="p">:</span>
          <span class="n">soa_arguments_dict</span><span class="p">[</span><span class="s">u&#39;argument_value&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">unicode</span><span class="p">(</span><span class="n">serial_number</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>

        <span class="n">row_count</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">UpdateRow</span><span class="p">(</span>
            <span class="s">&#39;record_arguments_records_assignments&#39;</span><span class="p">,</span> <span class="n">search_soa_dict</span><span class="p">,</span>
            <span class="n">soa_arguments_dict</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">row_count</span>

  <span class="k">def</span> <span class="nf">_AddRecordToIpIndex</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">record_type</span><span class="p">,</span> <span class="n">zone_name</span><span class="p">,</span> <span class="n">view_name</span><span class="p">,</span> <span class="n">record_id</span><span class="p">,</span>
                          <span class="n">target</span><span class="p">,</span> <span class="n">record_args_dict</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Add record to the ipv4 or ipv6 index.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      record_type: string of type of record</span>
<span class="sd">      zone_name: string of zone name</span>
<span class="sd">      view_name: string of view_name</span>
<span class="sd">      record_id: int of id for record</span>
<span class="sd">      target: string of the target of the record</span>
<span class="sd">      record_args_dict: dictionary of args for the record</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">ip</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">record_type</span> <span class="o">==</span> <span class="s">&#39;ptr&#39;</span> <span class="p">):</span>
      <span class="n">origin</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetZoneOrigins</span><span class="p">(</span><span class="n">zone_name</span><span class="p">,</span> <span class="n">view_name</span><span class="p">)[</span>
          <span class="n">zone_name</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
      <span class="n">ip</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">UnReverseIP</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s">.</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">target</span><span class="p">,</span> <span class="n">origin</span><span class="p">))</span>
      <span class="k">if</span><span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">data_validation_instance</span> <span class="ow">is</span> <span class="bp">None</span> <span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">InitDataValidation</span><span class="p">()</span>
      <span class="k">if</span><span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">data_validation_instance</span><span class="o">.</span><span class="n">isIPv4IPAddress</span><span class="p">(</span><span class="n">ip</span><span class="p">)</span> <span class="p">):</span>
        <span class="n">record_type</span> <span class="o">=</span> <span class="s">&#39;a&#39;</span>
      <span class="k">elif</span><span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">data_validation_instance</span><span class="o">.</span><span class="n">isIPv6IPAddress</span><span class="p">(</span><span class="n">ip</span><span class="p">)</span> <span class="p">):</span>
        <span class="n">record_type</span> <span class="o">=</span> <span class="s">&#39;aaaa&#39;</span>

    <span class="k">if</span><span class="p">(</span> <span class="n">record_type</span> <span class="o">==</span> <span class="s">&#39;a&#39;</span> <span class="p">):</span>
      <span class="k">if</span><span class="p">(</span> <span class="ow">not</span> <span class="n">ip</span> <span class="p">):</span>
        <span class="n">ip</span> <span class="o">=</span> <span class="n">record_args_dict</span><span class="p">[</span><span class="s">&#39;assignment_ip&#39;</span><span class="p">]</span>
      <span class="n">decimal_ip</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">IPy</span><span class="o">.</span><span class="n">IP</span><span class="p">(</span><span class="n">ip</span><span class="p">)</span><span class="o">.</span><span class="n">strDec</span><span class="p">())</span>
      <span class="n">ipv4_index_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;ipv4_dec_address&#39;</span><span class="p">:</span> <span class="n">decimal_ip</span><span class="p">,</span>
                         <span class="s">&#39;ipv4_index_record_id&#39;</span><span class="p">:</span> <span class="n">record_id</span><span class="p">}</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">MakeRow</span><span class="p">(</span><span class="s">&#39;ipv4_index&#39;</span><span class="p">,</span> <span class="n">ipv4_index_dict</span><span class="p">)</span>

    <span class="k">if</span><span class="p">(</span> <span class="n">record_type</span> <span class="o">==</span> <span class="s">&#39;aaaa&#39;</span> <span class="p">):</span>
      <span class="k">if</span><span class="p">(</span> <span class="ow">not</span> <span class="n">ip</span> <span class="p">):</span>
        <span class="n">ip</span> <span class="o">=</span> <span class="n">record_args_dict</span><span class="p">[</span><span class="s">&#39;assignment_ip&#39;</span><span class="p">]</span>
      <span class="n">ip_obj</span> <span class="o">=</span> <span class="n">IPy</span><span class="o">.</span><span class="n">IP</span><span class="p">(</span><span class="n">ip</span><span class="p">)</span>
      <span class="n">decimal_ip_lower</span> <span class="o">=</span> <span class="n">ip_obj</span><span class="o">.</span><span class="n">int</span><span class="p">()</span> <span class="o">&amp;</span> <span class="mh">0x0000000000000000ffffffffffffffff</span>
      <span class="n">decimal_ip_upper</span> <span class="o">=</span> <span class="n">ip_obj</span><span class="o">.</span><span class="n">int</span><span class="p">()</span> <span class="o">&gt;&gt;</span> <span class="mi">64</span>
      <span class="n">ipv6_index_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;ipv6_dec_upper&#39;</span><span class="p">:</span> <span class="n">decimal_ip_upper</span><span class="p">,</span>
                         <span class="s">&#39;ipv6_dec_lower&#39;</span><span class="p">:</span> <span class="n">decimal_ip_lower</span><span class="p">,</span>
                         <span class="s">&#39;ipv6_index_record_id&#39;</span><span class="p">:</span> <span class="n">record_id</span><span class="p">}</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">MakeRow</span><span class="p">(</span><span class="s">&#39;ipv6_index&#39;</span><span class="p">,</span> <span class="n">ipv6_index_dict</span><span class="p">)</span>


  <span class="k">def</span> <span class="nf">_MakeCredential</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">credential</span><span class="p">,</span> <span class="n">user_name</span><span class="p">,</span> <span class="n">last_used</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                      <span class="n">infinite_cred</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Create a credential.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      user_name: string of user name</span>
<span class="sd">      credential: a 36 character uuid string</span>
<span class="sd">      infinite_cred: bool of infinite time to live</span>
<span class="sd">      last_used: datetime of access</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">last_used</span> <span class="ow">is</span> <span class="bp">None</span> <span class="p">):</span>
      <span class="n">last_used</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">()</span>
    <span class="n">infinite_cred</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">infinite_cred</span><span class="p">)</span>
    <span class="n">credential_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;credential&#39;</span><span class="p">:</span> <span class="n">credential</span><span class="p">,</span>
                       <span class="s">&#39;credential_user_name&#39;</span><span class="p">:</span> <span class="n">user_name</span><span class="p">,</span>
                       <span class="s">&#39;infinite_cred&#39;</span><span class="p">:</span> <span class="n">infinite_cred</span><span class="p">,</span>
                       <span class="s">&#39;last_used_timestamp&#39;</span><span class="p">:</span> <span class="n">last_used</span><span class="p">}</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">MakeRow</span><span class="p">(</span><span class="s">&#39;credentials&#39;</span><span class="p">,</span> <span class="n">credential_dict</span><span class="p">)</span>
    <span class="k">except</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
      <span class="k">raise</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>

  <span class="k">def</span> <span class="nf">_ListCredentials</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">credential</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">user_name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                       <span class="n">infinite_cred</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">key_by_user</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Lists one or many credentials, if all args are None then list them all.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      credential: uuid string of credential</span>
<span class="sd">      user_name: string of user name</span>
<span class="sd">      infinite_cred: boolean of infinite time to live</span>
<span class="sd">      key_by_user: boolean to key by user rather than credential</span>

<span class="sd">    Output:</span>
<span class="sd">      dictionary: keyed_by_user=False, a dictionary keyed</span>
<span class="sd">        by credential string.</span>
<span class="sd">        example: {&#39;xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx&#39;:</span>
<span class="sd">                     {&#39;user_name&#39;: &#39;sharrell&#39;,</span>
<span class="sd">                      &#39;last_used_timestamp&#39;: 1970-10-10 23:00:00,</span>
<span class="sd">                      &#39;infinite_cred&#39;: True}}</span>

<span class="sd">        keyed by the user name</span>
<span class="sd">        example: {&#39;sharrell&#39;:</span>
<span class="sd">            {&#39;credential&#39;: &#39;xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx&#39;,</span>
<span class="sd">             &#39;last_used_timestamp&#39;: 1970:10-10 23:00:00,</span>
<span class="sd">             &#39;infinite_cred&#39;: True}}</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">credential_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;credential&#39;</span><span class="p">:</span> <span class="n">credential</span><span class="p">,</span>
                       <span class="s">&#39;credential_user_name&#39;</span><span class="p">:</span> <span class="n">user_name</span><span class="p">,</span>
                       <span class="s">&#39;last_used_timestamp&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>
                       <span class="s">&#39;infinite_cred&#39;</span><span class="p">:</span> <span class="n">infinite_cred</span><span class="p">}</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="n">credentials</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;credentials&#39;</span><span class="p">,</span> <span class="n">credential_dict</span><span class="p">)</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>

    <span class="n">credentials_dict</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">key_by_user</span> <span class="p">):</span>
      <span class="k">for</span> <span class="n">credential</span> <span class="ow">in</span> <span class="n">credentials</span><span class="p">:</span>
        <span class="n">credentials_dict</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="n">credential</span><span class="p">[</span><span class="s">&#39;credential_user_name&#39;</span><span class="p">]:</span>
            <span class="p">{</span><span class="s">u&#39;credential&#39;</span><span class="p">:</span> <span class="n">credential</span><span class="p">[</span><span class="s">&#39;credential&#39;</span><span class="p">],</span>
             <span class="s">u&#39;last_used_timestamp&#39;</span><span class="p">:</span> <span class="n">credential</span><span class="p">[</span><span class="s">&#39;last_used_timestamp&#39;</span><span class="p">],</span>
             <span class="s">u&#39;infinite_cred&#39;</span><span class="p">:</span> <span class="n">credential</span><span class="p">[</span><span class="s">&#39;infinite_cred&#39;</span><span class="p">]}})</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="k">for</span> <span class="n">credential</span> <span class="ow">in</span> <span class="n">credentials</span><span class="p">:</span>
        <span class="n">credentials_dict</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="n">credential</span><span class="p">[</span><span class="s">&#39;credential&#39;</span><span class="p">]:</span>
            <span class="p">{</span><span class="s">u&#39;user&#39;</span><span class="p">:</span> <span class="n">credential</span><span class="p">[</span><span class="s">&#39;credential_user_name&#39;</span><span class="p">],</span>
             <span class="s">u&#39;last_used_timestamp&#39;</span><span class="p">:</span> <span class="n">credential</span><span class="p">[</span><span class="s">&#39;last_used_timestamp&#39;</span><span class="p">],</span>
             <span class="s">u&#39;infinite_cred&#39;</span><span class="p">:</span> <span class="n">credential</span><span class="p">[</span><span class="s">&#39;infinite_cred&#39;</span><span class="p">]}})</span>

    <span class="k">return</span> <span class="n">credentials_dict</span>

  <span class="k">def</span> <span class="nf">_RemoveCredential</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">credential</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">user_name</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Removes a credential.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      credential: uuid strong of credential</span>
<span class="sd">      user_name: string of user name</span>

<span class="sd">    Raises:</span>
<span class="sd">      UnexpectedDataError: Must specify at least one of the two possible arguments.</span>

<span class="sd">    Outputs:</span>
<span class="sd">      int: number of rows modified</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">search_credential_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;credentials&#39;</span><span class="p">)</span>

    <span class="k">if</span> <span class="p">(</span> <span class="n">credential</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="p">):</span>
      <span class="n">search_credential_dict</span><span class="p">[</span><span class="s">&#39;credential&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">credential</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">user_name</span> <span class="ow">is</span> <span class="bp">None</span> <span class="p">):</span>
        <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">UnexpectedDataError</span><span class="p">(</span><span class="s">&#39;Must specify at least one of the two &#39;</span>
                               <span class="s">&#39;possible arguments&#39;</span><span class="p">)</span>
      <span class="n">search_credential_dict</span><span class="p">[</span><span class="s">&#39;credential_user_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">user_name</span>
    <span class="n">row_count</span> <span class="o">=</span> <span class="mi">0</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="n">found_credential</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;credentials&#39;</span><span class="p">,</span>
                                            <span class="n">search_credential_dict</span><span class="p">,</span>
                                            <span class="n">lock_rows</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">found_credential</span> <span class="p">):</span>
        <span class="c"># credential is a unique field, we know there is only one.</span>
        <span class="n">row_count</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">RemoveRow</span><span class="p">(</span><span class="s">&#39;credentials&#39;</span><span class="p">,</span>
                                                <span class="n">found_credential</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
    <span class="k">except</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
      <span class="k">raise</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>

    <span class="k">return</span> <span class="n">row_count</span>

  <span class="k">def</span> <span class="nf">_UpdateCredential</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">search_credential</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">search_user_name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                        <span class="n">update_credential</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Updates a credential.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      search_credential: uuid string of credential</span>
<span class="sd">      search_user_name: string of user name</span>
<span class="sd">      update_credential: uuid string of credential</span>

<span class="sd">    Outputs:</span>
<span class="sd">      int: number of rows modified</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">search_credential_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;credentials&#39;</span><span class="p">)</span>
    <span class="n">update_credential_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;credentials&#39;</span><span class="p">)</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">search_credential</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="p">):</span>
      <span class="n">search_credential_dict</span><span class="p">[</span><span class="s">&#39;credential&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">search_credential</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="n">search_credential_dict</span><span class="p">[</span><span class="s">&#39;credential_user_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">search_user_name</span>
    <span class="n">update_credential_dict</span><span class="p">[</span><span class="s">&#39;credential&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">update_credential</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="n">row_count</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">UpdateRow</span><span class="p">(</span><span class="s">&#39;credentials&#39;</span><span class="p">,</span>
                                             <span class="n">search_credential_dict</span><span class="p">,</span>
                                             <span class="n">update_credential_dict</span><span class="p">)</span>
    <span class="k">except</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
      <span class="k">raise</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>

    <span class="k">return</span> <span class="n">row_count</span>

<div class="viewcode-block" id="Core.MakeInfiniteCredential"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.MakeInfiniteCredential">[docs]</a>  <span class="k">def</span> <span class="nf">MakeInfiniteCredential</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">user_name</span><span class="p">,</span> <span class="n">credential</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Creates an infinite credential.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      user_name: string of user to create credential for.</span>

<span class="sd">    Outputs:</span>
<span class="sd">      string: credential string created</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="k">if</span><span class="p">(</span> <span class="n">credential</span> <span class="ow">is</span> <span class="bp">None</span> <span class="p">):</span>
      <span class="k">while</span><span class="p">(</span> <span class="bp">True</span> <span class="p">):</span>
        <span class="n">credential</span> <span class="o">=</span> <span class="nb">unicode</span><span class="p">(</span><span class="n">uuid</span><span class="o">.</span><span class="n">uuid4</span><span class="p">())</span>
        <span class="k">if</span><span class="p">(</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ListCredentials</span><span class="p">(</span><span class="n">credential</span><span class="p">)</span> <span class="p">):</span>
          <span class="k">break</span>
      <span class="c"># This will preserve the actual credential arg which is None in the</span>
      <span class="c"># audit args, while letting the replay args keep the actual value</span>
      <span class="n">current_args</span><span class="p">[</span><span class="s">&#39;replay_args&#39;</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">credential</span>

    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">_MakeCredential</span><span class="p">(</span><span class="n">credential</span><span class="p">,</span> <span class="n">user_name</span><span class="p">,</span> <span class="n">infinite_cred</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Core.ListCredentials"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.ListCredentials">[docs]</a>  <span class="k">def</span> <span class="nf">ListCredentials</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">credential</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">user_name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                      <span class="n">infinite_cred</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Lists infinte credentials.</span>

<span class="sd">    This function basically just calls _ListCredentials but runs Authorize</span>
<span class="sd">    before.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      credential: string of specific credential that is being searched for</span>
<span class="sd">      user_name: string of name of user that is being searched for</span>
<span class="sd">      infinite_cred: bool of search for infinite or non infinite creds</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="s">u&#39;ListCredentials&#39;</span><span class="p">)</span>
    <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ListCredentials</span><span class="p">(</span><span class="n">credential</span><span class="o">=</span><span class="n">credential</span><span class="p">,</span> <span class="n">user_name</span><span class="o">=</span><span class="n">user_name</span><span class="p">,</span>
                                 <span class="n">infinite_cred</span><span class="o">=</span><span class="n">infinite_cred</span><span class="p">,</span>
                                 <span class="n">key_by_user</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Core.RemoveCredential"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.RemoveCredential">[docs]</a>  <span class="k">def</span> <span class="nf">RemoveCredential</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">credential</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">user_name</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Removes a credential</span>

<span class="sd">    This function will call _RemoveCredential after Authorize and then log it.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      credential: string of credential to remove</span>
<span class="sd">      user_name: string of user name who has a credential to remove</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>

    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">_RemoveCredential</span><span class="p">(</span><span class="n">credential</span><span class="o">=</span><span class="n">credential</span><span class="p">,</span> <span class="n">user_name</span><span class="o">=</span><span class="n">user_name</span><span class="p">)</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Core.ListAuditLog"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.ListAuditLog">[docs]</a>  <span class="k">def</span> <span class="nf">ListAuditLog</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">user_name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">success</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                   <span class="n">begin_timestamp</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">end_timestamp</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Lists audit log</span>

<span class="sd">    Inputs:</span>
<span class="sd">      user_name: string of user name</span>
<span class="sd">      action: string of function</span>
<span class="sd">      success: intbool of success</span>
<span class="sd">      begin_timestamp: datetime object of beginning timestamp</span>
<span class="sd">      end_timestamp: datetime object of ending timestamp</span>
<span class="sd">    </span>
<span class="sd">    Raises:</span>
<span class="sd">      UnexpectedDataError: Missing begin_timestamp or end_timestamp.</span>

<span class="sd">    Outputs:</span>
<span class="sd">      dict: Dictionary of audit log</span>
<span class="sd">        ex: {&#39;action&#39;: u&#39;Action&#39;, &#39;data&#39;, u&#39;Data&#39;,</span>
<span class="sd">             &#39;audit_log_timestamp&#39;: datetime.datetime,</span>
<span class="sd">             &#39;audit_log_user_name&#39;: u&#39;username&#39;}</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="s">&#39;ListAuditLog&#39;</span><span class="p">)</span>
    <span class="k">if</span><span class="p">(</span> <span class="p">(</span><span class="n">begin_timestamp</span> <span class="ow">or</span> <span class="n">end_timestamp</span><span class="p">)</span> <span class="ow">and</span> <span class="ow">not</span>
        <span class="p">(</span><span class="n">begin_timestamp</span> <span class="ow">or</span> <span class="n">end_timestamp</span><span class="p">)</span> <span class="p">):</span>
      <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">UnexpectedDataError</span><span class="p">(</span>
          <span class="s">&#39;Missing begin_timestamp or end_timestamp.&#39;</span><span class="p">)</span>
    <span class="n">audit_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;audit_log_id&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span> <span class="s">&#39;audit_log_user_name&#39;</span><span class="p">:</span> <span class="n">user_name</span><span class="p">,</span>
                  <span class="s">&#39;action&#39;</span><span class="p">:</span> <span class="n">action</span><span class="p">,</span> <span class="s">&#39;data&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span> <span class="s">&#39;success&#39;</span><span class="p">:</span> <span class="n">success</span><span class="p">,</span>
                  <span class="s">&#39;audit_log_timestamp&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">}</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">begin_timestamp</span> <span class="ow">and</span> <span class="n">end_timestamp</span> <span class="p">):</span>
        <span class="n">audit_log_rows</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
            <span class="s">&#39;audit_log&#39;</span><span class="p">,</span> <span class="n">audit_dict</span><span class="p">,</span> <span class="n">column</span><span class="o">=</span><span class="s">&#39;audit_log_timestamp&#39;</span><span class="p">,</span>
            <span class="n">is_date</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span>
            <span class="n">range_values</span><span class="o">=</span><span class="p">(</span><span class="n">begin_timestamp</span><span class="p">,</span> <span class="n">end_timestamp</span><span class="p">))</span>
      <span class="k">else</span><span class="p">:</span>
        <span class="n">audit_log_rows</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;audit_log&#39;</span><span class="p">,</span> <span class="n">audit_dict</span><span class="p">)</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>

    <span class="k">return</span> <span class="n">audit_log_rows</span>
</div>
<div class="viewcode-block" id="Core.SetMaintenanceFlag"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.SetMaintenanceFlag">[docs]</a>  <span class="k">def</span> <span class="nf">SetMaintenanceFlag</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Sets maintenance flag</span>

<span class="sd">    Inputs:</span>
<span class="sd">      value: boolean of flag on or off</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="s">&#39;SetMaintenanceFlag&#39;</span><span class="p">)</span>

    <span class="n">search_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;lock_name&#39;</span><span class="p">:</span> <span class="s">u&#39;maintenance&#39;</span><span class="p">,</span> <span class="s">&#39;locked&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">}</span>
    <span class="n">update_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;lock_name&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span> <span class="s">&#39;locked&#39;</span><span class="p">:</span> <span class="nb">int</span><span class="p">(</span><span class="n">value</span><span class="p">)}</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">UpdateRow</span><span class="p">(</span><span class="s">&#39;locks&#39;</span><span class="p">,</span> <span class="n">search_dict</span><span class="p">,</span> <span class="n">update_dict</span><span class="p">)</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="Core.CheckMaintenanceFlag"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.Core.CheckMaintenanceFlag">[docs]</a>  <span class="k">def</span> <span class="nf">CheckMaintenanceFlag</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Checks maintenance flag</span>

<span class="sd">    Outputs:</span>
<span class="sd">      bool: value of flag on or off</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">CheckMaintenanceFlag</span><span class="p">()</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
</div></div>
<div class="viewcode-block" id="CheckCoreVersionMatches"><a class="viewcode-back" href="../../roster_core.html#roster_core.core.CheckCoreVersionMatches">[docs]</a><span class="k">def</span> <span class="nf">CheckCoreVersionMatches</span><span class="p">(</span><span class="n">version</span><span class="p">):</span>
  <span class="sd">&quot;&quot;&quot;Does a version check between core and calling module</span>

<span class="sd">  Inputs:</span>
<span class="sd">    version: version to check against core&#39;s version</span>
<span class="sd">  </span>
<span class="sd">  Raises:</span>
<span class="sd">    VersionDiscrepancyError: version mismatch with core version.</span>
<span class="sd">  &quot;&quot;&quot;</span>
  <span class="k">if</span><span class="p">(</span> <span class="n">version</span> <span class="o">!=</span> <span class="n">__version__</span> <span class="p">):</span>
    <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">VersionDiscrepancyError</span><span class="p">(</span>
        <span class="s">&#39;version </span><span class="si">%s</span><span class="s"> mismatch with core version </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">version</span><span class="p">,</span> <span class="n">__version__</span><span class="p">))</span></div>
</pre></div>

          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li><a href="../../index.html">Roster Core v0.18 documentation</a> &raquo;</li>
          <li><a href="../index.html" >Module code</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2013, Purdue University.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2b1.
    </div>
  </body>
</html>